在子 Recyclerview android 中禁用滚动 [英] Disable Scrolling in child Recyclerview android

查看:20
本文介绍了在子 Recyclerview android 中禁用滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局由一个父 RecyclerView 和一个子 RecyclerView 组成

I have a layout consists of a Parent RecyclerView with a sub Recyclerview in it

我知道将列表放在另一个列表中不好,但我必须这样做,以便我可以使用子列表功能,例如滑动和拖放

i know that it is not good to put a list inside another list but i have to so that i can use the sub list features like swiping and drag and drop

我的问题是子 Recyclerview 获得焦点并阻止父级在接触点位于其上时滚动只是我想要触摸是否垂直在子 Recyclerview 上父级向上和向下滚动,如果触摸是水平的或单击,则子 Recyclerview 列表项向左和向右滑动.对实现这一目标有什么帮助吗?

My issue is that the child Recyclerview gain focus and stops the parent from scrolling if the touch point was on it simply i want if the touch was vertically on the child Recyclerview the parent scrolls up and down and if the touch was horizontal or a click then the child Recyclerview list item swipes left and right. Any help to achieve this?

推荐答案

我终于找到了解决方案.

I finally found a solution.

创建自定义 LinearLayoutManager

Create Custom 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;
}
}

然后像这样实例化垂直滚动

Then instantiate it like this for vertical scrolling

CustomLinearLayoutManager customLayoutManager = new CustomLinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);

最后将自定义布局设置为回收器视图的布局管理器

Finally set the custom layout as layout manager of recycler view

recyclerView.setLayoutManager(customLayoutManager);

这篇关于在子 Recyclerview android 中禁用滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆