我正在尝试将 ESRI map 添加到我位于 NestedScrollView 中的 fragment 。它加载正常,但是当我移动 map 时,如果我删除 NestedScrollView,它不会顺利移动,一切正常。
这是我在 NestedScrollView 中的 ESRI map View
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/spacing_normal">
<com.esri.arcgisruntime.mapping.view.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.esri.arcgisruntime.mapping.view.MapView>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
我尝试通过将 customTouchListener 设置为来自 here 的 map View 喜欢:
MyTouchListener tl = new MyTouchListener(this, mMapView);
mMapView.setOnTouchListener(tl);
MyTouchListener 类:
class MyTouchListener(context: Context, m: MapView) : DefaultMapViewOnTouchListener(context, m) {
private var sv: NestedScrollView? = null
override fun onTouch(v: View?, event: MotionEvent): Boolean {
v?.performClick()
sv = v!!.findViewById(R.id.nestedScrollView)
val action = event.action
when (action) {
MotionEvent.ACTION_DOWN ->
// will disable the scrollview from being able to
// intercept the touch events for the mapview
sv?.requestDisallowInterceptTouchEvent(true)
MotionEvent.ACTION_UP ->
// gives control back over to the scrollview
sv?.requestDisallowInterceptTouchEvent(false)
}
super.onTouch(v, event)
return true
}
}
还是一样的问题, map 移动不流畅。
最佳答案
它将禁止 scrollView 拦截 mapView 的触摸事件
override fun onTouch(view: View?, event: MotionEvent?): Boolean {
activity?.nestedScrollView?.requestDisallowInterceptTouchEvent(true)
return super.onTouch(view, event)
}
也在 addViewpointChangedListener
中执行
mapView.addViewpointChangedListener {
activity?.nestedScrollView?.requestDisallowInterceptTouchEvent(true)
}
关于android - 嵌套 ScrollView 中的 ESRI map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53850779/