我有一个 ScrollView,里面有很多视图(TextView,按钮,...),最后有一个 osmdroid-mapview,它只是一个地图。当我触摸地图视图时,Android 不会移动地图(缩放或更改地图的位置),但会移动滚动视图。例如,我向上移动手指意味着地图应该向南移动。但滚动视图却向下移动。我的问题是:用户是否可以更改地图视图而不是滚动视图?我可以以某种方式阻止地图视图进行滚动交互吗?但地图视图仍然必须是滚动视图的一部分。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.osmdroid.views.MapView
android:id="@+id/mapBbox"
android:layout_width="373dp"
android:layout_height="349dp"
android:layout_marginTop="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.448"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioGroup" />
...
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
mapBbox.setNestedScrollingEnabled(false)
看看是否可以在 onCreate 中使用它。它的作用是禁用滚动视图的滚动行为
PS:
android:layout_width="373dp" << change to match parent
android:layout_height="349dp" << change to wrap content or a seperate value
在 onCreate() 方法中使用这段代码:
map.setOnTouchListener((v, event) -> {
@Override
public boolean onTouch(View v, MotionEvent event) {
// avoid nestedView or scrollView, scroll when it's child panning or zooming
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});