我在 ScrollView 上放置了一个 MapBox map , ScrollView 意味着我无法在 map 周围平移/缩放。
我不确定这是 MapBox 的错误还是我遗漏了一些可能很明显的东西?
我在 Github ( https://github.com/mapbox/react-native-mapbox-gl/issues/208 ) 中发现了这个问题,但正如我所说,我不确定这是否真的是一个错误,实际上只是我的实现存在问题。
最佳答案
这段代码可能会为您解决问题:
@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>
希望对您有所帮助!
关于java - 在 MapBox View 上平移/缩放时如何阻止 ScrollView 滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36651096/