简体   繁体   English

RecyclerView内的RecyclerView不滚动

[英]RecyclerView inside RecyclerView is not scrolling

I have a Recyclerview with GridLayoutManager whose child items may have a vertical RecyclerView inside it. 我有一个带有GridLayoutManager的Recyclerview,其子项目里面可能有一个垂直的RecyclerView。 Here is the screenshot: 这是截图:

在此输入图像描述

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. 它显示正确但内部Recyclerview不滚动,无论其中有多少项。 Can anyone suggest how to make internal and main RecyclerViews scroll? 任何人都可以建议如何使内部和主要RecyclerViews滚动?

I found the solution. 我找到了解决方案。 I just had to disable the touch event of the parent in case Recyclerview receives touch event. 我只需要在Recyclerview收到触摸事件的情况下禁用父级的触摸事件。 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);

I found the answer here: Recyclerview inside Scrollview 我在这里找到了答案: Scrollview内的Recyclerview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM