2020年10月6日 星期二

ScrollView 嵌套 RecyclerView 與其他 view 的滑動事件



目的:在 recyclerview 上方加個 textview,且要一起滑動

實作:


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

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

<TextView
android:id="@+id/tv_bookCount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:visibility="visible" />

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

</LinearLayout>
</androidx.core.widget.NestedScrollView>


在fragment:

rv.setNestedScrollingEnabled(false);



沒有留言:

張貼留言