在此之前佳簸,經(jīng)歷過(guò)ScrollView嵌套ScrollView滑動(dòng)沖突胯甩,ScrollView與ListView嵌套滑動(dòng)沖突等等迹辐,網(wǎng)上解決方法比較多暫不贅述了枪孩,RecyclerView出來(lái)已經(jīng)差不多2年了憔晒,ListView可以說(shuō)已經(jīng)成為了過(guò)去式了,現(xiàn)在開(kāi)發(fā)完全使用RecyclerView就行了蔑舞。
我親自試驗(yàn)過(guò)拒担,RecyclerView嵌套R(shí)ecyclerView是不存在滑動(dòng)沖突的,ScrollView嵌套R(shí)ecyclerView也會(huì)存在顯示不全的問(wèn)題攻询,滑動(dòng)也有一點(diǎn)點(diǎn)粘連的感覺(jué)不是太流暢从撼,NestedScrollView嵌套R(shí)ecyclerView不會(huì)存在顯示不全的問(wèn)題,代碼如下:
<?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>
上面的代碼只是簡(jiǎn)單的嵌套而已钧栖,但是還有一個(gè)小問(wèn)題低零,觸摸到RecyclerView的時(shí)候滑動(dòng)還有些粘連的感覺(jué),只需要在代碼中設(shè)置
mRecyclerView.setNestedScrollingEnabled(false);
就可以完美的解決這個(gè)問(wèn)題拯杠。
歡迎轉(zhuǎn)載掏婶,轉(zhuǎn)載請(qǐng)注明原文鏈接,謝謝配合L杜恪雄妥!