Android实现左右滑动页面

public class TestHD extends Activity implements OnGestureListener,
		OnDoubleTapListener 

 

@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		// TODO Auto-generated method stub
		if (e1.getX() > e2.getX()) {// move to left
			mViewFlipper.showNext();
		} else if (e1.getX() < e2.getX()) {
			mViewFlipper.setInAnimation(getApplicationContext(),
					R.anim.push_right_in);
			mViewFlipper.setOutAnimation(getApplicationContext(),
					R.anim.push_right_out);
			mViewFlipper.showPrevious();
			mViewFlipper.setInAnimation(getApplicationContext(),
					R.anim.push_left_in);
			mViewFlipper.setOutAnimation(getApplicationContext(),
					R.anim.push_left_out);
		} else {
			return false;
		}
		return true;

	}

 

@Override
	public boolean onTouchEvent(MotionEvent event) {
		return this.mGestureDetector.onTouchEvent(event);
	}

 

你可能感兴趣的:(android)