Fixing RecyclerView: How to fixe, Images Not Loading Properly on First Scroll, but Resolved When Returning to Position

40 Views Asked by At

I have created a view with two RecyclerViews and a ScrollView to prevent the RecyclerViews from moving up when the user clicks on an EditText. I have set the orientation for both recycler views as horizontal. However, I'm facing an issue where the RecyclerView used to display full images scrolls the first time, but the image does not display. However, when I scroll back to the same position again, the image shows up correctly. Any suggestion is appreciated thanks

enter image description here

enter image description here

code in XML

 <androidx.constraintlayout.widget.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/black">
   <ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginTop="@dimen/_12sdp"
    android:fillViewport="true"
    app:layout_constraintBottom_toTopOf="@+id/layoutEditText"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/constraintLayout2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:fitsSystemWindows="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvShowImage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/closeImage"
            android:layout_width="@dimen/_26sdp"
            android:layout_height="@dimen/_26sdp"
            android:layout_margin="@dimen/_12sdp"
            android:src="@drawable/ic_cross"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvShowAndDeleteImages"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="@dimen/_12sdp"
            android:padding="@dimen/_2sdp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.498"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintVertical_bias="1.0" />
    </androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>
<include
    android:id="@+id/layoutEditText"
    layout="@layout/edit_text_item"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />
  </androidx.constraintlayout.widget.ConstraintLayout>

code ima adapter that is used to show full images

     <androidx.constraintlayout.widget.ConstraintLayout 
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/showImage"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:focusableInTouchMode="true"
        android:clickable="true"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
0

There are 0 best solutions below