SwipeRefreshLayout 内的谷歌地图视图

GoogleMaps view inside SwipeRefreshLayout

我需要在 SwipeRefreshLayout 中放置 google 地图视图,问题是 SwipeRefreshLayout 在触摸事件时覆盖 google 地图。当我尝试向上滚动地图时,SwipeRefreshLayout 事件被触发。我如何在滚动 google 地图时禁用 SwipeRefreshLayout 事件?

我在 Shiba J 提出的 this 线程中找到了这个问题的解决方案。我扩展了 SwipeRefreshLayout 并覆盖了 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;
    }
}