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;

猜你喜欢

转载自blog.csdn.net/qq_35605213/article/details/85715207