第一種:在你的RecyclerView上外邊嵌套一層RelativeLayout,
然后添加屬性?android:descendantFocusability="blocksDescendants",
如:
<RelativeLayout
? ? android:layout_width="match_parent"
? ? android:layout_height="wrap_content"
? ? android:descendantFocusability="blocksDescendants">
? ? <android.support.v7.widget.RecyclerView
? ? ? ? android:id="@+id/rv_meeting"
? ? ? ? android:paddingLeft="15dp"
? ? ? ? android:paddingRight="15dp"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"/>
</RelativeLayout>
PS:既然提到了這個屬性就說下它的意思吧,知道的同學再復習一遍唄,鞏固鞏固更牢靠。
屬性android:descendantFocusability的含義是:當一個view獲取焦點時,定義ViewGroup和其子控件兩者之間的關(guān)系。
它一共有3個屬性值,它們分別是:
beforeDescendants:viewGroup會優(yōu)先子類控件而獲取焦點
afterDescendants:viewGroup只有當子類控件不需要獲取焦點的時候才去獲取焦點
blocksDescendants:viewGroup會覆蓋子類控件而直接獲取焦點
第二種方法:
首先在xml布局中將你的ScrollView替換成android.support.v4.widget.NestedScrollView,
并在java代碼中設(shè)置recyclerView.setNestedScrollingEnabled(false);