MapView inside a ScrollView?

前端 未结 9 1249
时光取名叫无心
时光取名叫无心 2020-11-28 04:18

I would like to have a MapView inside a ScrollView, however when I try to scroll the map, the ScrollView takes priority! Is there a way to give the MapView priority when scr

9条回答
  •  失恋的感觉
    2020-11-28 04:42

    If somebody wants this class in kotlin.
    I used dispatchTouchEvent like suggested by @rotem

    class CustomMapView : MapView {
               constructor(context: Context):
                super(context)
        constructor(context: Context, googleMapOptions: GoogleMapOptions):
                super(context, googleMapOptions)
        constructor(context: Context, attributeSet: AttributeSet):
                super(context, attributeSet)
        constructor(context: Context, attributeSet: AttributeSet, int: Int):
                super(context, attributeSet, int)
    
        override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
            Log.d("CustomWebView", "touchevent")
            when(event?.action) {
                MotionEvent.ACTION_UP -> {
                    Log.d("CustomWebView", "disallow Intercept")
                    parent.requestDisallowInterceptTouchEvent(false)
                }
                MotionEvent.ACTION_DOWN -> {
                    Log.d("CustomWebView", "allow Intercept")
                    parent.requestDisallowInterceptTouchEvent(true)
                }
            }
            return super.dispatchTouchEvent(event)
        }
    }
    

提交回复
热议问题