簡體   English   中英

Android 在 RecycleView 中處理 Google Map 的滾動

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM