@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return this.detector.onTouchEvent(event);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
if (e1.getX() - e2.getX() > 120) {
this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.drawable.left_in));
this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.drawable.left_out));
this.flipper.showNext();
return true;
} else if (e1.getX() - e2.getX() < -120) {
this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.drawable.right_in));
this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.drawable.right_out));
this.flipper.showPrevious();
return true;
} else if (e1.getY() - e2.getY() > 200) {
this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.drawable.push_up_in));
this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.drawable.push_up_out));
this.flipper.showNext();
return true;
} else if (e1.getY() - e2.getY() < -200) {
this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.drawable.push_down_in));
this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.drawable.push_down_out));
this.flipper.showPrevious();
return true;
}
return false;
}
重写两个事件,一个是onTouchEvent函数,一个是onFling函数
这样就可以实现翻页效果了。