自定义MapView类,重写其onInterceptTouchEvent方法。
代码如下:
public class MyMapView extends MapView {
private long lastTouchTime = -1;
public MyMapView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
long thisTime = System.currentTimeMillis();
if (thisTime - lastTouchTime < 250) {
this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
lastTouchTime = -1;
}else{
lastTouchTime = thisTime;
}
}
return super.onInterceptTouchEvent(ev);
}
}
本文介绍了一种自定义MapView的方法,通过重写onInterceptTouchEvent方法实现双击缩放的功能。具体做法是在ACTION_DOWN时记录当前时间,并判断两次点击的时间间隔是否小于250毫秒来决定是否触发缩放。
4200

被折叠的 条评论
为什么被折叠?



