本文介绍了里面滚动型谷歌地图API V2 SupportMapFragment - 用户无法滚动地图垂直的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把谷歌地图滚动视图里面,这样用户可以滚动其他内容看地图。问题是,这种滚动视图是吃了所有的垂直触摸事件,所以地图的UI体验变得非常怪异。

I am trying to put a Google map inside a scroll view, so that the user can scroll down other contents to see the map. The problem is that this scroll view is eating up all the vertical touching events, so the UI experience of map becomes very weird.

我知道,在谷歌地图的V1,您可以覆盖onTouch,或setOnTouchListener在MotionEvent.ACTION_DOWN打电话requestDisallowInterceptTouchEvent。我试图实施类似的技巧与V2无济于事。

I know that in V1 of the google map, you could override onTouch, or setOnTouchListener to call requestDisallowInterceptTouchEvent upon MotionEvent.ACTION_DOWN. I have tried to implement the similar trick with V2 to no avail.

到目前为止,我曾尝试:

So far I have tried:

  • 覆盖SupportMapFragment了,里面onCreateView,用于查看
  • 设置一个触摸监听器
  • 在调用SupportMapFragment实例.getView(),然后setOnTouchListener
  • 在周围相对布局或框架布局包裹,掩盖了片段与透明的视图或ImageView的
  • Override SupportMapFragment, and inside onCreateView, set a on touch listener for the View
  • call .getView() of a SupportMapFragment instance, then setOnTouchListener
  • Wrap around relative layout or frame layout, mask the fragment with a transparent view or imageview

所有这些补救滚动的问题。我失去了一些东西呢?如果任何人有一个地图内滚动视图工作的例子,你能不能请您分享code例子吗?

None of these remedied the scrolling problem. Am I missing something here? If anyone has a working example of a map inside scrolling view, could you please kindly share code example?

推荐答案

感谢您的建议,

在很多尝试和错误,脱下我的头发,并发誓在显示器和我的Andr​​oid手机测试很差,我已经想通了,如果我自定义滚动型,覆盖onInterceptTouchEvent在我们​​返回false时,该事件是在地图上查看不管是什么,然后在地图上的滚动不发生预期。

After much try-and-error, pulling off my hairs and swearing at monitor and my poor Android test phone, I've figured that if I customise ScrollView, override onInterceptTouchEvent in which we return false when the event is on a map view no matter what, then the scrolling on a map does happen as expected.

class MyScrollView(c:Context, a:AttributeSet) extends ScrollView(c,a) {
  val parent = c.asInstanceOf[MyActivity]
  override def onInterceptTouchEvent(ev:MotionEvent):Boolean = {
    var bound:Rect = new Rect()
    parent.mMap.getHitRect(bound)
    if(bound.contains(ev.getX.toInt,ev.getY.toInt))
      false
    else
      super.onInterceptTouchEvent(ev)
  }
}

这code是在Scala中,但你的想法。

This code is in Scala but you get the idea.

请注意,我用的原始地图视图(如图结束了android-sdks\extras\google\google_play_services\samples\maps\src\com\example\mapdemoRawMapViewDemoActivity.java).想你可以做pretty的多少同样的事情片段,我只是从来没有摆在首位喜欢的片段。

Note I've ended up using a raw map view (as shown in android-sdks\extras\google\google_play_services\samples\maps\src\com\example\mapdemoRawMapViewDemoActivity.java). Guess you can do the pretty much same thing with fragments, I just never liked fragments in the first place.

我认为谷歌欠我一个道歉。

I think Google owes me an apology.

这篇关于里面滚动型谷歌地图API V2 SupportMapFragment - 用户无法滚动地图垂直的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 16:06