반응형
Double click/tap detection on android's MapView
If there is a cleaner way to do it, please share :)
1. Override the default MapView with your own implementation;
2. Override the onInterceptTouchEvent method;
3. Check if the last event was also a click and happened close by (say in the last 250ms);
3.1. If so, it’s a double tap; do whatever you want (in this case I zoom in on the last clicked point);
3.2. If not, ignore :)
Here’s the code (Sorry for the formatting mess, but... :)):
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import com.google.android.maps.MapView;
public class MyMapView extends MapView {
private long lastTouchTime = -1;
public MyMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
long thisTime = System.currentTimeMillis();
if (thisTime - lastTouchTime < 250) {
// Double tap
this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
lastTouchTime = -1;
} else {
// Too slow :)
lastTouchTime = thisTime;
}
}
반응형
'프로그래밍(~2017) > 안드로이드' 카테고리의 다른 글
[android 안드로이드] activity in activity 혹은 activity in fragment 혹은 태블릿에서 fragment 를 이용하여 mapview 여러개 뛰우기 (0) | 2012.01.06 |
---|---|
[android 안드로이드] Activity 를 dialog 처럼 사용하기 (1) | 2012.01.05 |
[android 안드로이드] ontouchlistener 구현시 제스쳐 편하게 구현하기(클릭구현, 더블클릭구현 등등) (0) | 2012.01.03 |
android 안드로이드 intent 인텐트 변수 정리 (0) | 2011.09.26 |
XmlPullParser 사용시 유의법(규칙) (9) | 2011.09.22 |