简体   繁体   English

Android 在 RecycleView 中处理 Google Map 的滚动

[英]Android handle scrolling of Google Map inside RecycleView

Haven't found a question/answer for this.还没有找到这个问题/答案。 When you put a Google Map inside a RecycleView (I'm using MapView inside a ViewHolder), the scrolling only works from left-to-right.当您将 Google Map 放入 RecycleView(我在 ViewHolder 中使用 MapView)时,滚动只能从左到右进行。 Up-down scrolling is taken up by the RecycleView.上下滚动由 RecycleView 占用。 Is there a way to provide normal (one finger) scrolling for the map view?有没有办法为 map 视图提供正常(一根手指)滚动?

Thanks谢谢

RecycleView get by default up and down surface scroll. 默认情况下,RecycleView获取上,下表面滚动。 You have to separate it from the main view. 您必须将其与主视图分开。 By using NestedScrollView you can get this. 通过使用NestedScrollView,您可以获取此信息。 Put your googlemap in NestedScrollView. 将您的googlemap放在NestedScrollView中。

This is how I've solved this -这就是我解决这个问题的方法 -

I've created a custom view extending mapView and override dispatchTouchEvent()我创建了一个扩展 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
    }
}

and used this to my xml -并将其用于我的 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM