NestedScrollView+RecyclerView優雅的解決滑動衝突問題
阿新 • • 發佈:2018-12-21
在此之前,經歷過ScrollView巢狀ScrollView滑動衝突,ScrollView與ListView巢狀滑動衝突等等,網上解決方法比較多暫不贅述了,RecyclerView出來已經差不多2年了,ListView可以說已經成為了過去式了,現在開發完全使用RecyclerView就行了。
我親自試驗過,RecyclerView巢狀RecyclerView是不存在滑動衝突的,ScrollView巢狀RecyclerView也會存在顯示不全的問題,滑動也有一點點粘連的感覺不是太流暢,NestedScrollView巢狀RecyclerView不會存在顯示不全的問題,程式碼如下:
上面的程式碼只是簡單的巢狀而已,但是還有一個小問題,觸控到RecyclerView的時候滑動還有些粘連的感覺,只需要在程式碼中設定
就可以完美的解決這個問題。
我親自試驗過,RecyclerView巢狀RecyclerView是不存在滑動衝突的,ScrollView巢狀RecyclerView也會存在顯示不全的問題,滑動也有一點點粘連的感覺不是太流暢,NestedScrollView巢狀RecyclerView不會存在顯示不全的問題,程式碼如下:
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 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:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/app_name"/> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/app_name"/> </LinearLayout> </android.support.v4.widget.NestedScrollView>
上面的程式碼只是簡單的巢狀而已,但是還有一個小問題,觸控到RecyclerView的時候滑動還有些粘連的感覺,只需要在程式碼中設定
mRecyclerView.setNestedScrollingEnabled(false);
就可以完美的解決這個問題。
原文:http://www.jianshu.com/p/791c0a4acc1c