我的布局由一个父 RecyclerView 和一个子 Recyclerview 组成
我知道将列表放在另一个列表中并不好,但我必须这样做才能使用子列表功能,例如滑动和拖放
我的问题是子 Recyclerview 获得焦点并阻止父级滚动如果触摸点在它上面 如果触摸是垂直地在子 Recyclerview 上,我只是想要 父级上下滚动,如果触摸是水平的或单击,则子级 Recyclerview 列表项左右滑动。 有什么帮助来实现这一点吗?
最佳答案
我终于找到了解决办法。
创建自定义 LinearLayoutManager
public class CustomLinearLayoutManager extends LinearLayoutManager {
public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
// it will always pass false to RecyclerView when calling "canScrollVertically()" method.
@Override
public boolean canScrollVertically() {
return false;
}
}
然后像这样实例化它以进行垂直滚动
CustomLinearLayoutManager customLayoutManager = new CustomLinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
最后将自定义布局设置为recycler view的布局管理器
recyclerView.setLayoutManager(customLayoutManager);
关于android - 在子 Recyclerview android 中禁用滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30222310/