在我們日常開發中經常會用到ScrollView與RecyclerView的組合,但是這種組合有時會出現滑動不流暢的問題,也就是卡頓現象
布局如下:
<ScrollView
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="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerView">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
我們只需要給RecyclerView設置下面兩個屬性就可以了 注意:(如果是多個RecyclerView,每個都需要設置,並不是設置一個就行了)
//解決滑動沖突、滑動不流暢
recyclerView.setHasFixedSize(http://www.amjmh.com);
recyclerView.setNestedScrollingEnabled(false);
