4

I need to place google map view inside SwipeRefreshLayout, the problem is that SwipeRefreshLayout overwrites google maps on touch event. When i try to scroll map upwards SwipeRefreshLayout event is getting triggered. How could i disable SwipeRefreshLayout events when i scroll google maps?

Michał Witanowski
  • 602
  • 3
  • 8
  • 22

1 Answers1

0

I found solution to this problem in this thread proposed by Shiba J. I extended SwipeRefreshLayout and overrode onInterceptTouchEvent.

public class OverviewSwipeRefreshLayout extends SwipeRefreshLayout {

    public OverviewSwipeRefreshLayout(Context context) {
        super(context);
    }

    public OverviewSwipeRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        final int action = ev.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                super.onTouchEvent(ev);
                break;
            case MotionEvent.ACTION_MOVE:
                return false;
            case MotionEvent.ACTION_CANCEL:
                super.onTouchEvent(ev);
                break;
            case MotionEvent.ACTION_UP:
                return false;
            default:
                break;
        }

        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        super.onTouchEvent(ev);
        return true;
    }
}
Community
  • 1
  • 1
Michał Witanowski
  • 602
  • 3
  • 8
  • 22