RecyclerView中的RecyclerView不滚动 [英] RecyclerView inside RecyclerView is not scrolling

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

问题描述

我有一个带有GridLayoutManager的Recyclerview,其子项内部可能有一个垂直的RecyclerView.这是屏幕截图:

I have a Recyclerview with GridLayoutManager whose child items may have a vertical RecyclerView inside it. Here is the screenshot:

我已经为这种情况创建了适配器.它可以正确显示它,但是不管里面有多少物品,内部的Recyclerview都不会滚动.谁能建议如何使内部和主要RecyclerViews滚动?

I have created adapters for this scenario. It shows it properly but internal Recyclerview is not scrolling no matter how many items are inside it. Can anyone suggest how to make internal and main RecyclerViews scroll?

推荐答案

我找到了解决方案.我只需要禁用父级的touch事件,以防Recyclerview收到touch事件.这是对我有用的代码片段:

I found the solution. I just had to disable the touch event of the parent in case Recyclerview receives touch event. Here is the code snippet that worked for me:

RecyclerView.OnItemTouchListener mScrollTouchListener = new RecyclerView.OnItemTouchListener() {
    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
        int action = e.getAction();
        switch (action) {
            case MotionEvent.ACTION_MOVE:
                rv.getParent().requestDisallowInterceptTouchEvent(true);
                break;
        }
        return false;
    }

    @Override
    public void onTouchEvent(RecyclerView rv, MotionEvent e) {

    }

    @Override
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

    }
}; 

recyclerView.addOnItemTouchListener(mScrollTouchListener);

我在这里找到了答案: Scrollview内部的Recyclerview

I found the answer here: Recyclerview inside Scrollview

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

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