更新时间:2022-11-02 09:46:26
感谢您的建议,
在很多尝试和错误,脱下我的头发,并发誓在显示器和我的Android手机测试很差,我已经想通了,如果我自定义滚动型,覆盖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.