我有一個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