Android ScrollView與RecyclerView滑動沖突問題


在我們日常開發中經常會用到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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM