Nested RecyclerView. How to prevent parent RecyclerView from getting scrolled while child RecyclerView is scrolling?

前端 未结 14 1276
余生分开走
余生分开走 2020-12-07 21:24

I am trying to implement a horizontal recyclerview and each item of the recyclerview will be a vertical recyclerview with a grid layou

相关标签:
14条回答
  • 2020-12-07 21:50

    extend a custom layout manager like this

     public class CustomLayoutManager extends LinearLayoutManager {
     private boolean isScrollEnabled = true;
    
     public CustomGridLayoutManager(Context context) {
     super(context);
            }
      @Override
     public boolean canScrollVertically() {
     return false;
     }
    }
    

    Set the layout manager to this "Custom layout Manager"

    0 讨论(0)
  • 2020-12-07 21:51

    Set the listener to nested RecyclerView

     View.OnTouchListener listener = new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getAction() == MotionEvent.ACTION_MOVE
                                ) {
                            v.getParent().requestDisallowInterceptTouchEvent(true);
    
                        } else {
                            v.getParent().requestDisallowInterceptTouchEvent(false);
    
                        }
                        return false;
                    }
                };
    
                mRecyclerView.setOnTouchListener(listener);
    
    0 讨论(0)
提交回复
热议问题