ScrollView 中的 MapView?
我希望在 ScrollView 中有一个 MapView,但是当我尝试滚动地图时,ScrollView 优先!有没有办法在地图内滚动时给予 MapView 优先权,否则给予 ScrollView 优先权?
谢谢!
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 scrolling inside the map, and the ScrollView otherwise?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我已经遇到同样的问题 10 天了,但几分钟前我得到了解决方案!
这是解决方案。
我制作了一个自定义 MapView 并像这样重写 onTouchEvent() 。
I have had a same problem for 10 days, but I got a solution a few minutes ago!!
Here is the solution.
I made a custom MapView and override onTouchEvent() like this.
一种更好/更简单的方法来做到这一点,无需操纵单独的触摸事件。
如果您使用 MapView,这将起作用:
完整类:
如果您使用 MapFragment,则可以将片段放入自定义视图中,并在
dispatchTouchEvent()
中创建requestDisallowInterceptTouchEvent
代码>调用。A better/simpler way to do this without manipulating individual touch events.
This will work if you are using MapView:
Full class:
If you are using a MapFragment then you can put the fragment in a Custom View, and in the
dispatchTouchEvent()
make therequestDisallowInterceptTouchEvent
call.制作自己的地图并使用它。它完全适合我。
在你的布局 xml 中,
Make your own map and use it. It works fully for me.
In your layout xml,
对于那些想要完整工作代码的人。这是
自定义地图视图类
活动布局xml
在您的活动或片段中实例化自定义地图类
就是这样
For those who want the whole working code . here it is
Custom map view class
Activity layout xml
Instantiating the custom map class in your activity or fragment
That's it enjoy
您可以像这样创建自定义 MapView:
You can create a custom MapView like this:
我尝试过重写 MapView.onTouchEvent(...),但它对我不起作用。
这是运行良好的代码(覆盖 MapView.onInterceptTouchEvent(...)):
I've tried with overriding MapView.onTouchEvent(...), but it didn't work for me.
Here is code which works well (overriding MapView.onInterceptTouchEvent(...)):
如果有人想要 kotlin 中的这个课程。
我按照@rotem的建议使用了dispatchTouchEvent
If somebody wants this class in kotlin.
I used
dispatchTouchEvent
like suggested by @rotem您可以简单地将 MapView 放入布局本身并覆盖 onTouch 或设置 Click-Listener - 对我来说最简单的方法,因为我需要触摸 ScrollView 中的整个 MapView。
You can simply put the MapView in a Layout itself and override onTouch or set an Click-Listener - easiest way for me since i needed a touch on the whole MapView in my ScrollView.
如果您在滚动视图中有地图视图,那么您必须向地图视图明确提及以下参数:
If you have mapview in scroll view then you have to explicity mention the follwing paramets to the MapView:
在 Kotlin 中对 Mapbox 的 MapView 进行扩展(同时遵循 @fupduck 的代码):
可以在 XML 中轻松使用,如下所示:
Extension to Mapbox's MapView in Kotlin (while following code from @fupduck):
Which can be easily usable in XML as: