ScrollView嵌套RecyclerView(解决在Android6.0系统上RecyclerView可以单独捕获滑动事件的问题)

最近在做项目中发现在真机测试中,由于开发测试一直用的4.4的真机做测试,以至于导致发现项目在Android6.0.1系统上的RecyclerView和ScrollView滑动中都可以上下滑动的问题。。。。。。直接上解决代码!

/**
 * 解决首页scrolview嵌套recyclerview在Android6.0系统上出现的recyclerview也能捕获滑动事件问题
 * Created by Administrator on 2016/12/16 0016.
 */
public class CustomStaggeredGridLayoutManager extends StaggeredGridLayoutManager {
    private boolean isScrollEnabled = true;

    public CustomStaggeredGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }


    public CustomStaggeredGridLayoutManager(int spanCount, int orientation) {
        super(spanCount, orientation);
    }


    public void setScrollEnabled(boolean flag) {
        this.isScrollEnabled = flag;
    }

    @Override
    public boolean canScrollVertically() {
        //Similarly you can customize "canScrollHorizontally()" for managing horizontal scroll
        return isScrollEnabled && super.canScrollVertically();
    }
}
  CustomStaggeredGridLayoutManager manager=new CustomStaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        manager.setScrollEnabled(false);
        mRecyclerview.setLayoutManager(manager);

这里说下:这里的父类用的StaggeredGridLayoutManager (瀑布流)也可以用LinearLayoutManager、GridLayoutManager换下就好

IT群: 472148690这是我建的群号哈

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值