我在开发安卓应用。在我的应用程序中,我想通过滑动和点击选项卡按钮从第一个活动移动到第二个活动。
所以请告诉我,当我从右向左切换时,如何使用我的应用程序中的swipe移动到下一个活动,以及当我从左向右切换时,如何返回第一个活动。
谢谢。
发布于 2013-03-06 13:25:34
您可以使用GestureDector来获取左右滑动动作的回调。http://developer.android.com/reference/android/view/GestureDetector.html
发布于 2013-03-06 13:26:48
让您活动实现OnGestureListener
然后重写此方法
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Intent i=new Intent(GroupScreen.this,TimeLineScreen.class);
i.putExtra("clear", true);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
overridePendingTransition( R.anim.slide_in_left, R.anim.slide_out_left );
} catch (Exception e) {
// nothing
}
return true;
}https://stackoverflow.com/questions/15239531
复制相似问题