我有两个活动,我打算用滑动手势启动。但是活动之间的过渡是正常的活动启动,但是我想要在viewpager中发生一些事情,因为你会横向滑动。它是如何做到的?这是我的SwipeGestures代码..
公共类SwipeActivity扩展了AppCompatActivity {
private GestureDetectorCompat gestureDetectorCompat;
@Override
public boolean onTouchEvent(MotionEvent event){
this.gestureDetectorCompat.onTouchEvent(event);
return super.onTouchEvent(event);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swipe);
gestureDetectorCompat = new GestureDetectorCompat(this, new GestureDetector.OnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if(e2.getX()<e1.getX()){
Intent intent = new Intent(SwipeActivity.this,BottomSheetActivity.class);
startActivity(intent);
finish();
}
return true;
}
});
}
}
现在,当我通过滑动启动意图时,我想要一些ViewPager会发生的事情(这意味着应该能够在滑动时显示下一个屏幕)。
三江源, 杰