本文介绍了禁用滚动儿童Recyclerview机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局由父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 itsimply i want if the touch was vertically on the child Recyclerviewthe 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 layoutmanager of recycler view

recyclerView.setLayoutManager(customLayoutManager);

这篇关于禁用滚动儿童Recyclerview机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 04:23