我有一个ViewFlipper应该对一个投掷手势作出反应,但事实并非如此.
活动
@Override
public void onCreate(Bundle savedInstanceState) {
...
listView = this.getListView();
detector = new GestureDetector(this, new FlingGestureListener(listView));
...
}
Run Code Online (Sandbox Code Playgroud)
FlingGestureListener
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
int pos = source.pointToPosition(Math.round(e1.getX()), Math.round(e1.getY()));
View v = source.getChildAt(pos - source.getFirstVisiblePosition());
System.out.println("fling: x=" + velocityX + " y=" + velocityY);
try {
IFlingable flingable = (IFlingable) v;
if(velocityY > -200 && velocityY < 200) {
if(velocityX < 0)
flingable.fling(IFlingable.RIGHT_TO_LEFT);
else if(velocityX > 0)
flingable.fling(IFlingable.LEFT_TO_RIGHT);
}
} catch(Exception e) …Run Code Online (Sandbox Code Playgroud)