Reputation: 315
Hello and sorry for not adding the images on this page, I don't have enough reputation yet
This is how it's supposed to look and this is how it's displaying in the recyclerView, as you can see I want to have the image on the left with the centered text on the right, how can I achieve this?
Here's the code for the item layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imgRowCompany"
android:layout_width="115dp"
android:layout_height="80dp"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:clickable="false"
android:src="@drawable/library_icon"
android:visibility="visible"
app:civ_border_color="@color/Blue"
app:civ_border_width="2.5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txtRowCompanyName"
android:layout_width="0dp"
android:layout_height="46dp"
android:layout_centerVertical="true"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:text="CompanyName"
android:textColor="#000000"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imgRowCompany"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
The recyclerAdapter code:
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.recycler_item,parent,false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
}
@Override//Number od items to be returned
public int getItemCount() {
return 10;
}
static class ViewHolder extends RecyclerView.ViewHolder {
CircleImageView imageRowCompany;
TextView companyName;
public ViewHolder(@NonNull View itemView) {
super(itemView);
imageRowCompany=itemView.findViewById(R.id.imgRowCompany);
companyName=itemView.findViewById(R.id.txtRowCompanyName);
}
}
}
And the recyclerView code :
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CompanyLibrary"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Any help would be appreciated, thanks!
Upvotes: 1
Views: 103
Reputation: 576
The image you've posted is on RTL device. End to end and start to start is working expected manner, if you want to show in the your manner then use
app:layout_constraintRight_toRightOf="parent" instead of
app:layout_constraintEnd_toEndOf="parent"
and
app:layout_constraintLeft_toLeftOf="parent" instead of
app:layout_constraintStart_toStartOf="parent"
Upvotes: 2