在MapBox视图上平移/缩放时,如何阻止ScrollView滚动?

nin*_*ght 3 java android scrollview mapbox

我在滚动视图上放置了一个MapBox地图,并且滚动视图意味着我无法在地图上平移/缩放。

我不确定这是否是MapBox的错误,或者我是否缺少某些可能很明显的东西?

我在Github(https://github.com/mapbox/react-native-mapbox-gl/issues/208)中发现了这个问题,但是正如我所说的,我不确定这实际上是一个错误,实际上仅仅是一个我的实施存在问题。

cam*_*ace 7

此代码段可能为您解决了该问题:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final ScrollView sv = (ScrollView) findViewById(R.id.scrollView);

    // Setup the MapView
    mapView = (MapView) findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);

    // ....

    mapView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_MOVE:
                    sv.requestDisallowInterceptTouchEvent(true);
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                    sv.requestDisallowInterceptTouchEvent(false);
                    break;
            }
            return mapView.onTouchEvent(event);
        }
    });
Run Code Online (Sandbox Code Playgroud)

最后,这是我的XML

ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.cameron.mapboxplayground.MainActivity"
android:id="@+id/scrollView">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- Set the starting camera position and map style using xml-->
    <com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        mapbox:access_token="@string/accessToken"
        mapbox:style_url="@string/style_light"
        mapbox:center_latitude="40.7359"
        mapbox:center_longitude="-74.0151"
        mapbox:zoom="10"/>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助你!