Scroll not working for multiple RecyclerView in BottomSheet

前端 未结 6 734
天命终不由人
天命终不由人 2020-12-14 09:04

I implemented BottomSheet using the DialogFragment approach. I have a TabLayout and ViewPager in the BottomSheet

6条回答
  •  无人及你
    2020-12-14 09:50

    use this view as root view:

    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    import android.widget.LinearLayout;
    
    public class DisallowInterceptView extends LinearLayout {
        public DisallowInterceptView(Context context) {
            super(context);
            requestDisallowInterceptTouchEvent(true);
        }
    
        public DisallowInterceptView(Context context, AttributeSet attrs) {
            super(context, attrs);
            requestDisallowInterceptTouchEvent(true);
        }
    
        public DisallowInterceptView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            requestDisallowInterceptTouchEvent(true);
        }
    
    
        public boolean dispatchTouchEvent(MotionEvent ev) {
            getParent().requestDisallowInterceptTouchEvent(true);
            return super.dispatchTouchEvent(ev);
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_MOVE:
                    requestDisallowInterceptTouchEvent(true);
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                    requestDisallowInterceptTouchEvent(false);
                    break;
            }
            return super.onTouchEvent(event);
        }
    
    }
    

    then in your layout that used for bottmSheet:

    
    
    
    
    
        ...
    
    
    
    

提交回复
热议问题