I'm getting a list of users from a back-end server and I display in a RecyclerView. I have a layout file for each row. This is what I have tried:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data class="UserDataBinding">
<variable
name="user"
type="com.example.myapp.User" />
</data>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_margin="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/poster_path_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:scaleType="centerCrop" />
//Other views
</androidx.cardview.widget.CardView>
</layout>
My goal is to display only the profile pictures. The problem is that even if I set the layout_height
to 150dp
, the picture is displayed very small. Even if I increase the height nothing happens. How to set the CardView/ImageView to have a fixed height?
Edit:
I found the solution. I forgot to inflate the view. This line solved the problem:
ListItemBinding binding = DataBindingUtil.inflate(layoutInflater, R.layout.list_item, viewGroup, false);
As @DavidWasser suggested, I added the solution as an answer to my own question. The problem was that I forgot to inflate the view. This line solved my problem:
ListItemBinding binding = DataBindingUtil.inflate(layoutInflater, R.layout.list_item, viewGroup, false);