与地图片段交互时禁用 swiperefreshlayout 和 scrollview

Disable swiperefreshlayout and scrollview when interacting with a map fragment

我目前有以下布局高级布局

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swipeRefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <android.support.constraint.ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="81dp">

            ...

            <FrameLayout
                android:id="@+id/location_container"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginEnd="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginStart="8dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView3"
                app:layout_constraintVertical_bias="0.0">

                <fragment
                    android:id="@+id/fragment_location"
                    android:name="com.nissanshare.vehicleinfo.VehicleLocationFragment"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="8dp"
                    android:tag="fragment_vehicleInfo"
                    tools:layout="@layout/fragment_vehicle_info_location" />

                <View
                    android:id="@+id/transparent_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:color/transparent" />
            </FrameLayout>

            ...

        </android.support.constraint.ConstraintLayout>
    </ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

在我的代码中有以下方法

mTouchInterceptor是布局中的transparent_view

private void setupTouchInterceptor() {
        mTouchInterceptor.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action) {
                    case MotionEvent.ACTION_DOWN:
                        Log.d(TAG, ".onTouch:DOWN");
                        // Disallow ScrollView to intercept touch events.
                        mScrollView.requestDisallowInterceptTouchEvent(true);
                        mSwipeRefreshLayout.requestDisallowInterceptTouchEvent(true);

                        return false;

                    case MotionEvent.ACTION_UP:
                        Log.d(TAG, ".onTouch:UP");
                        // Allow ScrollView to intercept touch events.

                        mScrollView.requestDisallowInterceptTouchEvent(false);
                        mSwipeRefreshLayout.requestDisallowInterceptTouchEvent(false);

                        return true;

                    case MotionEvent.ACTION_MOVE:
                        Log.d(TAG, ".onTouch:MOVE");
                        mScrollView.requestDisallowInterceptTouchEvent(true);
                        mSwipeRefreshLayout.requestDisallowInterceptTouchEvent(true);

                        return false;

                    default:
                        return true;
                }
            }
        });
    }

这与我在不使用 SwipeRefreshLayout 的情况下使用 scrollview 时使用的代码相同,并且可以完美运行。但是,在添加 SwipeRefreshLayout 时,它似乎不尊重对 requestDisallowInterceptTouchEvent 的调用。如何防止 SwipeRefreshLayout 在与地图交互时刷新。

只需要将 ScrollView 更改为 android.support.v4.widget.NestedScrollView