在scrollview中使用mapbox,scrollview滑动到页面中放置mapbox的位置

eri*_*ric 1 android scrollview mapbox

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

我想看到的是:

然而奇怪的事情是这样的:

cam*_*ace 5

如果我正确理解您的问题,那么您在滚动视图中平移/缩放地图视图时遇到问题吗?最近这个问题被问了很多...

此代码片段可能会为您解决问题:

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

希望这可以帮助你!