Android Studio

리사이클러뷰(Recyclerview) 스크롤 시 밀림

리콜 2022. 12. 6. 01:03

리사이클러 뷰를 사용하여 영화 리스트를 출력하였다. 하지만 스크롤한 뒤 올라갔을때 이전 리스트들이 올라가 있는 경우가 있었다. 

스크롤 한뒤 위로 올라갔을때

해결하기 위해 다른 곳을 찾아보니 여러원인 들과 해결 방법이 있었으나 나의 경우에는 xml을 잘못 만들었던 것이었다.

리사이클러뷰에 들어갈 요소인 item_search_poster의 xml에 습관적으로 ConstraintLayout을 자동으로 만들어 주는 infer Constraints 버튼을 눌렀었는데 이를 통해 ConstarintLayout이 생겼어서 그랬다.

따라서 Code상에서 맨위와 아래의 

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
</androidx.constraintlayout.widget.ConstraintLayout>

을 삭제해준다.

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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_margin="5dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/poster_image_view"
        android:background="@drawable/poster_rounded_corner"
        android:layout_width="120dp"
        android:padding="5dp"
        android:layout_height="200dp" />
    </LinearLayout>

따라서 다음과 같이 리사이클러뷰에 들어갈 이미지 뷰를 설정해준다.

반응형