Android 嵌套XRecyclerView滑动迟缓以及上拉不好用解决办法

首先我们ScrollView要嵌套XrecyclerView等列表控件时,如果不需要上拉刷新可以直接使用ScrollView,但是有上拉刷新的需求时我们就需要选用NestedScrollView。话不多说,看代码。

 



        
        

        

第一种ScrollView嵌套不需要上拉的列表控件:

    1. //解决ScrollView嵌套RecyclerView滑动迟缓问题
        mEvaluateList.setHasFixedSize(true);
        mEvaluateList.setNestedScrollingEnabled(false);

    2.重写RecyclerView的管理器
       LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }

        };

  mEvaluateList.setLayoutManager(linearLayoutManager );

以上两种都可以实现ScrollView嵌套RecyclerView或者ListView等滑动迟缓的问题。

第二种ScrollView嵌套需要上拉的列表控件核心代码():

 

//LinearLayoutManager是线性布局,setOrientation可以设置他的方向是横向还是纵向。
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mEvaluateList.setLayoutManager(layoutManager);
mEvaluateList.setPullRefreshEnabled(false);//设置XrecyclerView禁止下拉刷新


//解决ScrollView嵌套RecyclerView滑动迟缓问题
mEvaluateList.setHasFixedSize(true);
mEvaluateList.setNestedScrollingEnabled(false);

Scrollview.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
    @Override
    public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
        if (scrollY > oldScrollY) {
            // 向下滑动
        }

        if (scrollY < oldScrollY) {
            // 向上滑动
        }

        if (scrollY == 0) {
            // 顶部
        }

        if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
            // 上拉刷新实现
        }
    }
});

如果NestedScrollView嵌套XrecyclerView后进入页面直接跳到列表最低部,在根部局加一行属性:android:descendantFocusability="blocksDescendants"

你可能感兴趣的:(android)