RecyclerView Android : Alternative to setIsRecyclable(false)

Viewed 14

With the given ViewHolder,I intend to display Pictures in a recyclerView and keep pictures displayed in with their natural ratio .To do so , i call in the holder

 LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) container.getLayoutParams();
            layoutParams.width = width;
            layoutParams.height = height;

and then display Picasso (Glide has the same results)


<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:background="@color/white"
    android:gravity="center_horizontal"
    android:orientation="vertical">



    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/container">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:visibility="visible" />

    </androidx.constraintlayout.widget.ConstraintLayout>




</LinearLayout>

Now I know this is not the only way to display pictures, but it underlines an issue i would like to be able to handle , so please do not ask to change the display method .

If i load the recycler , pictures appear properlly but after scrolling they are resized for no reason . Setting holder.setIsRecyclable(false) solves the issue . If this switch exists , i guess this is for cases like these . Is their a way to handle this case without using the switch ? (i tried to delete cache, i tried onViewRecycled) . The question is not about displaying pictures another way , it is about handling isRecyclable, thank you .

0 Answers
Related