本文介绍了在scrollview中使用mapbox,scrollview滑动到页面中放置mapbox的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,当我在scrollview中使用mapbox时,scrollview会滑动到mapbox在页面中的位置,但是我想一眼就能看到页面的顶部,而不是mapbox.顺便说一句,我正在使用Mapbox 4.0.0 Android SDK.

Now, when I use mapbox in scrollview, scrollview would slide to the position where mapbox is located in the page, but I want to see the top of the page at the first sight, not the mapbox. BTW, I am using Mapbox 4.0.0 Android SDK.

我想看的是:

但是奇怪的是,如下:

推荐答案

如果我正确理解了您的问题,则在滚动视图时,是否会在平移/缩放mapview时遇到问题?这个问题最近在这里问了很多...

If I understand your question correctly, you are having issues panning/zooming the mapview while it is in a scrollview? This questions been asked here a lot lately...

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

This snippet of code might resolve the issue for you:

@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

Lastly, heres my 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>

希望这对您有所帮助!

这篇关于在scrollview中使用mapbox,scrollview滑动到页面中放置mapbox的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 10:32