你可能必須結合幾種技術來實現你想要的。
爲了捕捉平移,我會嘗試覆蓋您的MapViews onTouchEvent()或者dispatchTouchEvent(),並偵聽MotionEvent.ACTION_UP事件。
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction()==MotionEvent.ACTION_UP) {
// Call your procedure here
}
return super.onTouchEvent(ev);
}
如果你想在掃視期間打電話給你的方法,我認爲你必須去尋找平移運動覆蓋兩個相同的方法之一:當用戶從屏幕上擡起手指,這是觸發。事情是這樣的:
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (event.getHistorySize() < 1)
return; // First call, no history
// Get difference in position since previous move event
float diffX = event.getX() - event.getHistoricalX(event.getHistorySize() - 1);
float diffY = event.getY() - event.getHistoricalY(event.getHistorySize() - 1);
if (Math.abs(diffX) > 0.5f || Math.abs(diffY) > 0.5f) {
/* Position has changed substantially, so this is probably a drag action.
Call your procedure here. */
}
}
}
爲了檢測變焦水平的變化可以覆蓋dispatchDraw:
int oldZoomLevel=-1;
public void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (getZoomLevel() != oldZoomLevel) {
// Call your procedure here
oldZoomLevel = getZoomLevel();
}
}
看起來這應該是一個內置的事件,但我想我會處理一些生活他們..謝謝! – Mzzzzzz