[英]Android handle scrolling of Google Map inside RecycleView
还没有找到这个问题/答案。 当您将 Google Map 放入 RecycleView(我在 ViewHolder 中使用 MapView)时,滚动只能从左到右进行。 上下滚动由 RecycleView 占用。 有没有办法为 map 视图提供正常(一根手指)滚动?
谢谢
默认情况下,RecycleView获取上,下表面滚动。 您必须将其与主视图分开。 通过使用NestedScrollView,您可以获取此信息。 将您的googlemap放在NestedScrollView中。
这就是我解决这个问题的方法 -
我创建了一个扩展 mapView 并覆盖 dispatchTouchEvent() 的自定义视图
class CustomMapView(context: Context, attrs: AttributeSet?): MapView(context, attrs) {
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
this.performClick()
when (ev.action) {
MotionEvent.ACTION_DOWN -> // Disallow ScrollView to intercept touch events.
this.parent.requestDisallowInterceptTouchEvent(true)
MotionEvent.ACTION_UP -> // Allow ScrollView to intercept touch events.
this.parent.requestDisallowInterceptTouchEvent(false)
}
// Handle MapView's touch events.
super.dispatchTouchEvent(ev)
return true
}
}
并将其用于我的 xml -
<com.demo.android.demo.ui.base.customviews.CustomMapView
android:id="@+id/map_placeholder"
android:layout_width="0dp"
android:layout_height="700dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
map:mapType="none" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.