Reputation: 305
I have a recyclerview and it shows a list of images. My need is to fit its width according to the width of parent i tried many codes but i am unable to do it .
Also tried scaletype = " centrecrop"
recycler view
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/adsRV_AD"
android:overScrollMode="never"
android:clipToPadding="false"
/>
</layout>
My item layout is
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:background="@drawable/bg_rounded_img"
android:outlineProvider="background"
android:src="@drawable/booknow"
android:adjustViewBounds="true"
android:id="@+id/icon"
/>
</layout>
Result : My references : How to scale an Image in ImageView to keep the aspect ratio
ImageView doesn't fill entire width
Scale Image to fill ImageView width and keep aspect ratio
Resizing ImageView to fit to aspect ratio
Scale ImageView to fit screen width/height while maintaining aspect ratio
RecyclerVIew item width doesn't fill screen width
Upvotes: 0
Views: 371
Reputation: 43
The problem might not be in the item layout but in the RecyclerView layout.
Try to be sure that the item usese the full width in the RecyclerView.
Upvotes: 1