This is my desired goal:
I want to show my grid elements in 3 rows using recyclerview. I also have a fixed image size in dp 120dpx120dp. but i want my mesh. Elements filled the entire vertical space so that there was no space in the recyclerView. so I used this layout for elements:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<android.support.v7.widget.CardView
android:id="@+id/view_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical"
app:elevation="10dp">
<LinearLayout
android:id="@+id/image_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="120dp"
android:layout_height="120dp"
android:scaleType="centerCrop"/>
<ir.per.ttf.PersianTextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="end"
android:singleLine="true"
android:textSize="16sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout
<P βbut what I see looks like this and the image is not cropped in the center!

but, reducing the image size to 100dpx100dp, my RecyclerView does not populate Items:

and I canβt achieve the desired look.
this is how i use my adapter:
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 3,
LinearLayoutManager.VERTICAL, false);
gridLayoutManager.setReverseLayout(true);
holder.horizonrtalItemRecyclerView.setLayoutManager(gridLayoutManager);
RecyclerChambersAdapter recyclerAdapter = new RecyclerChambersAdapter(context, items.get(position),3);
holder.horizonrtalItemRecyclerView.setAdapter(recyclerAdapter);
and this is on the view view holder:
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
RecyclerChambersItemViewHolder holder = (RecyclerChambersItemViewHolder) viewHolder;
try {
holder.setmyClass(myClasses.get(position));
holder.setTitle(myClasses.get(position).getName());
holder.setId(myClasses.get(position).getId());
holder.setItemImageSrc(myClasses.get(position).getPhoto().getUrl().toString());
} catch (Exception ex) {
holder.setItemImageSrc("");
ex.printStackTrace();
}
}