作者lovelycateye (我还想要更多力量)
看板AndroidDev
标题[分享] 将MapView放在ScrollView内
时间Wed Nov 21 18:09:29 2012
因为ScrollView会上下卷动,所以当点到地图要拖移时
会发生地图的拖移事件跑到ScrollView的卷动去,造成无法上下卷动。
横向卷动也会因此而卡卡的。
解决方法当然不是我想到的:
http://stackoverflow.com/questions/6546108/mapview-inside-a-scrollview
自己继承MapView做下面这些
@Override
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
// Handle MapView's touch events.
super.onTouchEvent(ev);
return true;
}
Layout会类似:
<ScrollView ...>
<LinearLayout>
<MapView .../>
<TextView .../>
...
</LinearLayout>
</ScrollView>
--
儿:台湾为何没在过万圣节?
父:傻孩子…台湾天天都是万圣节啊~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.99.182.229