谷歌地图触摸底部对话框 [英] Google map touch on bottom sheet dialog

查看:63
本文介绍了谷歌地图触摸底部对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的底部工作表对话框的顶部有一个google map片段.我禁用了底部工作表行为上的可拖动触摸操作,以便可以控制地图.问题是由于禁用了底部工作表的可拖动性,因此无法使用向上或向下触摸动作来滚动地图.我本来是想在用户触摸地图时禁用底部工作表行为的触摸操作,但是我不知道该怎么做.我该如何解决?

I have a google map fragment on the top of my bottom sheet dialog. I disabled the draggable touch action on the bottom sheet behavior so that I could control the map. The problem is that I can't scroll the map using up or down touch actions because of my bottom sheet draggable disabled. I was thinking to disable the touch action of the bottom sheet behavior when the user touches the map but I don't know how to do this. How can I fix this?

推荐答案

我有一个BottomSheetDialogFragment(父View),其中包含SupportMapFragment(子代View).平移地图仅适用于水平手势.正如OP所述,这是因为BottomSheetMap触摸事件在垂直手势方面存在冲突.

I have a BottomSheetDialogFragment (parent View) that contains SupportMapFragment (child View). Panning the map works only for horizontal gestures. As OP mentioned, this is because BottomSheet and Map touch events are in conflict when it comes to vertical gestures.

这就是我的处理方式.我的BottomSheetDialogFragment实现了OnMapReadyCallbackGoogleMap.OnCameraMoveStartedListener.

This is how I handled it. My BottomSheetDialogFragment implements OnMapReadyCallback and GoogleMap.OnCameraMoveStartedListener.

override fun onMapReady(p0: GoogleMap) {
    p0.setOnCameraMoveStartedListener(this)
}

override fun onCameraMoveStarted(reason: Int) {
    when(reason) {
        GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE -> {
            // The user gestured on the map
            childView?.parent?.requestDisallowInterceptTouchEvent(true)
        }
        GoogleMap.OnCameraMoveStartedListener.REASON_API_ANIMATION -> {
            // The user tapped something on the map
            childView?.parent?.requestDisallowInterceptTouchEvent(true)
        }
        GoogleMap.OnCameraMoveStartedListener.REASON_DEVELOPER_ANIMATION -> {
            // The app moved the camera
            childView?.parent?.requestDisallowInterceptTouchEvent(true)
        }
    }
}

设置为true时,requestDisallowInterceptTouchEvent()不允许父级View拦截子级View的触摸事件.现在,我可以在底部工作表对话框片段中放大/缩小地图(水平和垂直手势).

When set as true, requestDisallowInterceptTouchEvent() does not allow the parent View to intercept with the touch events of the child View. I can now zoom in/out the map (horizontal and vertical gestures) in my bottom sheet dialog fragment.

这篇关于谷歌地图触摸底部对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆