@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
hit_scrollx = view.getScrollX();
hit_scrolly = view.getScrollY();
hit_touchx = (int) event.getX();
hit_touchy = (int) event.getY();
break;
case MotionEvent.ACTION_UP:
int x = (int) event.getX();
int y = (int) event.getY();
if (x<hit_touchx-5 || x>hit_touchx+5 || y<hit_touchy-5 || y>hit_touchy+5)
scrollAbsolute(hit_scrollx+hit_touchx-x, hit_scrolly+hit_touchy-y);
break;
}
return(true);
}
這假設你有自己的scrollAbsolute這確實剪裁爲您的應用和使用View.scrollTo。這是爲具有主滾動視圖的活動而設計的。它捕獲所有觸摸事件。 「5」是爲了防止在無意義的觸摸上進行不必要的刷新。