我有一个MapBox地图放置在滚动视图上,滚动视图意味着我无法在地图上平移/缩放。如何在平移/缩放MapBox视图时停止滚动浏览?
我不确定这是MapBox的错误还是我错过了某些东西,可能很明显?
我发现在Github(https://github.com/mapbox/react-native-mapbox-gl/issues/208)中提出这个问题,但正如我所说,我不确定这实际上是一个错误,实际上只是我的实现问题。
我有一个MapBox地图放置在滚动视图上,滚动视图意味着我无法在地图上平移/缩放。如何在平移/缩放MapBox视图时停止滚动浏览?
我不确定这是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>
希望这可以帮助你!
完美。我需要设置onTouchListener事件。再次感谢您提供及时的答复。前些天你也回答了我的问题。保持良好的工作! MapBox一直很棒。 – nineteeneightyeight
这应该在示例页面上进行。 Thx你,你救了我的一天:) – dagatsoin
你可以发布你的活动的XML,所以我可以检讨它吗? – cammace