Android ScrollView嵌套Recyclerview滑動卡頓,松手即停問題解決;


假如你的布局類似這樣的:

  <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </android.support.v7.widget.RecyclerView>
    </ScrollView>

展示沒有問題,但是滑動的時候有卡頓問題,松手就停止滑動,感覺特別不爽,加上下面的代碼試試:

        recyclerView.setHasFixedSize(true);
        recyclerView.setNestedScrollingEnabled(false);

大概就是讓recyclerview的高度或寬度設置為最大不允許復用Item,然后禁止recyclerview滑動;

如果仍然卡頓,再試試這個:

recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });

從LayoutManager層面禁止滑動,如果是橫向的改為Horizontal;


免責聲明!

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



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