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

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

 

<android.support.v4.widget.NestedScrollView
    android:id="@+id/StudingDetails_scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never"
    android:scrollbars="none">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants">
        <com.jcodecraeer.xrecyclerview.XRecyclerView
            android:id="@+id/StudingDetails_evaluate_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:overScrollMode="never"
            android:scrollbars="none"
            />

        </RelativeLayout>
</android.support.v4.widget.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"

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值