Outer Recyclerview not receiving scroll events of inner Recyclerview

后端 未结 3 1758
谎友^
谎友^ 2020-12-16 18:55

I followed this tutorial to implement the behaviors for both hiding the toolbar and the FAB when scrolled: https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-

3条回答
  •  被撕碎了的回忆
    2020-12-16 19:26

    Hank Moody comment actually lead me to the correct answer - thanks Hank!

    This is how I solved my problem:

    1. Create a 'Scroll Through' recyclerview where the parent will receive all the scroll events of the child by doing this:

      public class ScrollThroughRecyclerView extends RecyclerView {
          public ScrollThroughRecyclerView(Context context) {
              super(context);
          }
      
          public ScrollThroughRecyclerView(Context context, AttributeSet attrs) {
              super(context, attrs);
          }
      
          public ScrollThroughRecyclerView(Context context, AttributeSet attrs, int defStyle) {
              super(context, attrs, defStyle);
          }
      
          @Override
          public boolean dispatchTouchEvent(MotionEvent ev){
              //true - block scrolling of child and allow scrolling for parent recycler
              return true;
          }
      }
      
    2. Use this custom recyclerview in your xml or in your java code and the scroll events will be passed correctly to your parent recyclerview which will activate the app scrollbehavior.

提交回复
热议问题