Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic image height in recycler view

I want to load images with dynamic height using Glide. I have an ImageView whose height is wrap_content and width is match_parent. When the recycler view loads the first time. The first image has a larger height than the rest of the images. My larger height image loads fine without any pixelation when I scroll down the view gets recycled and when I scroll back to top to first larger image it gets pixelated I think when the view gets recycled glide is using smaller recycler imageview height for downsampling the larger height image due to which its getting pixelated. I don't want to use setRecyclable (false) on recyclerview. Here's the implementation

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/drc_imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:src="@color/OFF_WHITE" />
</LinearLayout>

For loading the image

GlideApp
                .with(context)
                .asBitmap()
                .fitCenter()
                .load(absoluteHomeList.get(position - 1).getDynamic_card_url())
                .into(holder.dynamicImageView);

Here are the images for reference In first image when is not recycled image is loading properly without pixelating

In second image i scrolled recycler view down and back to top the first image gets pixelated

like image 993
Jaskaran Singh Avatar asked Sep 02 '25 06:09

Jaskaran Singh


1 Answers

Before loading image using glide use

holder.dynamicImageView.layout(0,0,0,0);
like image 123
Abhijit Hadkar Avatar answered Sep 04 '25 22:09

Abhijit Hadkar