ListView inside SwipeRefreshLayout inside Drawer (Layout): does not block the scroll direction

The ListView blocks its scroll direction at the start of the scroll. This works great with this configuration:

DrawerLayout ListView 

When I scroll up / down, the list scrolls. When I scroll left, the drawer closes: excellent. When I start shooting down and then change direction, the initial direction (horizontal / vertical) is blocked.

However, if I wrap the list in SwipeRefreshLayout as follows:

 DrawerLayout SwipeRefreshLayout ListView 

.. then locking the scroll / scroll direction no longer works. When I scroll up / down and then a little left / right, the list scrolls and the box also moves. The latter is not what I want.

Any suggestions on how to revert to the previous behavior using SwipeRefreshLayout?

+4
source share
3 answers

I had the same problem, but with RecyclerView instead of ListView. The simplest fix is ​​to expand the SwipeRefreshLayout, and if a downward movement is detected, inform the parent (box) layout so that it does not intercept events (for example, a sliding box).

 import android.content.Context; import android.support.v4.widget.SwipeRefreshLayout; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.ViewConfiguration; public class DrawerSwipeRefreshLayout extends SwipeRefreshLayout { private int touchSlop; private float initialDownY; public DrawerSwipeRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); touchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } @Override public boolean onInterceptTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: initialDownY = event.getY(); break; case MotionEvent.ACTION_MOVE: final float eventY = event.getY(); float yDiff = Math.abs(eventY - initialDownY); if (yDiff > touchSlop) { getParent().requestDisallowInterceptTouchEvent(true); } } return super.onInterceptTouchEvent(event); } } 
+1
source

What you can try with the Gesture Detector is to find whether the napkin is horizontal or vertical. If its vertical gives a touch event to view the list, otherwise DrawerLayout.

0
source

I am using the support library version "23.2.1" and I do not have this problem.

0
source

All Articles