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

3
我在滚动视图上放置了一个MapBox地图,但是由于滚动视图的存在,我无法在地图周围进行平移/缩放。
我不确定这是否是MapBox的错误,还是我漏掉了一些可能很明显的东西?
我在Github上找到了这个问题(https://github.com/mapbox/react-native-mapbox-gl/issues/208),但是正如我所说,我不确定这实际上是一个错误,而且可能只是我的实现问题。

你能否发布你的活动XML文件,以便我可以审核它? - cammace
1个回答

8
这段代码可能会解决你的问题: ```html

这段代码可能会解决您的问题:

```
@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);
        }
    });

最后,这是我的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>

希望这能帮到您!

很好。我需要设置onTouchListener事件。再次感谢您的快速回答。您前几天也回答了我的问题。继续保持良好的工作!MapBox非常棒。 - nineteeneightyeight
这应该发生在示例页面上。谢谢你,你救了我的一天 :) - dagatsoin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接