与地图片段交互时禁用卷帘刷新布局和滚动视图



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

<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>

在我的代码中,我有以下方法

布局中的transparent_view mTouchInterceptor

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的情况下使用滚动视图时使用的代码相同,并且可以完美运行。但是,在添加滑动刷新布局时,它似乎不尊重对requestDisallowInterceptTouchEvent的调用。如何防止卷帘刷新布局在与地图交互时刷新。

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

最新更新