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这是我建的群号哈

你可能感兴趣的:(Android,android,测试)