touch



public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// 当手指按下的时候
x1 = event.getX();
y1 = event.getY();
}
if (event.getAction() == MotionEvent.ACTION_UP) {
// 当手指离开的时候
x2 = event.getX();
y2 = event.getY();
if (x1 - x2 > 50) { // 向左滑
if (isxin) {
vf.setInAnimation(ButtonList_activity.this,
R.anim.in_leftright);
vf.setOutAnimation(ButtonList_activity.this,
R.anim.out_leftright);
vf.showPrevious();
isxin = false;
isre = true;
zuixin.setBackgroundColor(Color.WHITE);


}
} else if (x2 - x1 > 50) { // 向右滑
if (isre) {
vf.setInAnimation(ButtonList_activity.this,
R.anim.in_rightleft);
vf.setOutAnimation(ButtonList_activity.this,
R.anim.out_rightleft);
vf.showNext();
zuire.setBackgroundColor(Color.WHITE);
isre = false;
isxin = true;
}
}
}
return super.onTouchEvent(event);
}


public boolean onTouch(View arg0, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// 当手指按下的时候
x1 = event.getX();
y1 = event.getY();
}
if (event.getAction() == MotionEvent.ACTION_UP) {
// 当手指离开的时候
x2 = event.getX();
y2 = event.getY();
if (x1 - x2 > 50) {
if (isxin) {
vf.setInAnimation(ButtonList_activity.this,
R.anim.in_leftright);
vf.setOutAnimation(ButtonList_activity.this,
R.anim.out_leftright);
vf.showPrevious();
isxin = false;
isre = true;
zuixin.setBackgroundColor(Color.WHITE);
}
} else if (x2 - x1 > 50) { // "向右滑",
if (isre) {
vf.setInAnimation(ButtonList_activity.this,
R.anim.in_rightleft);
vf.setOutAnimation(ButtonList_activity.this,
R.anim.out_rightleft);
vf.showNext();
zuire.setBackgroundColor(Color.WHITE);
isre = false;
isxin = true;
}
}
}
return super.onTouchEvent(event);
}

你可能感兴趣的:(touch)