Programming/Android

안드로이드 #12 ScrollView 안에 RecyclerView 사용하기

Alxious 2020. 6. 10. 11:05

앱을 만들다 보면 ScrollView 안에 RecyclerView를 사용할 때가 있다.

 

예를 들면, 커뮤니티에서 사용하는 게시판이 있다.

그런데 ScrollView 안에 RecylcerView를 사용하게 되면

ScrollView의 스크롤 

RecyclerView의 스크롤이 따로따로 다 움직이게 된다.

 

이를 해결하기 위해서는 

ScrollView를 NestedScrollView로 사용하면 된다

 

<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

        <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

    </LinearLayout>

</androidx.core.widget.NestedScrollView>