privateGestureDetector mGestureDetector;
privateint verticalMinDistance = 180;
privateint minVelocity = 0;
privatevoid initGesture() {
mGestureDetector = newGestureDetector((OnGestureListener) this);
}
publicboolean onFling(MotionEvent e1, MotionEvent e2, floatvelocityX, floatvelocityY) {
if(e1.getX() - e2.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity) {
// 切换Activity
// Intent intent = new Intent(ViewSnsActivity.this, UpdateStatusActivity.class);
// startActivity(intent);
//Toast.makeText(this, "向左手势", Toast.LENGTH_SHORT).show();
}elseif (e2.getX() - e1.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity) {
// 切换Activity
// Intent intent = new Intent(ViewSnsActivity.this, UpdateStatusActivity.class);
// startActivity(intent);
//Toast.makeText(this, "向右手势", Toast.LENGTH_SHORT).show();
finish();
//activty切换动画
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
returnfalse;
}
@Override
publicvoid onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
publicboolean onScroll(MotionEvent arg0, MotionEvent arg1, floatarg2,
floatarg3) {
// TODO Auto-generated method stub
returnfalse;
}
@Override
publicvoid onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
publicboolean onSingleTapUp(MotionEvent arg0) {
// TODO Auto-generated method stub
returnfalse;
}
@Override
publicboolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
// 触摸事件设置位mGestureDetector
returnmGestureDetector.onTouchEvent(event);
}
@Override
publicboolean onDown(MotionEvent arg0) {
// TODO Auto-generated method stub
returnfalse;
}
@Override
publicboolean dispatchTouchEvent(MotionEvent ev) {
// 把触摸事件分配给GestureDetector,重点一
mGestureDetector.onTouchEvent(ev);
returnsuper.dispatchTouchEvent(ev);
}