How do I stop the ScrollView from scrolling when panning/zooming on the MapBox View?… here is a solution to the problem.
How do I stop the ScrollView from scrolling when panning/zooming on the MapBox View?
I
put a MapBox map on top of the ScrollView, and the ScrollView means I can’t pan/zoom around the map.
I’m not sure if this is a bug with MapBox or am I missing something that might be obvious?
I’m > on Github ( ) found this issue, but as I said, I’m not sure if this is really a bug, it’s really just a problem with my implementation.
Solution
This code may solve the problem 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);
}
});
Finally, here is 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>
Hope this helps!