Adds left and right gesture recognition and activity gesture recognition for the activity.
Added left and right gesture recognition for the activity in android development, for example, sliding right to close the current page
/** For left and right gestures * 1. copy the following content to the target Activity * 2. the onCreate () of the target Activity calls initGesture () * 3. the target Activity must be implements OnTouchListener, OnGestureListener */private listener; private int verticalMinDistance = 180; private int minVelocity = 0; private void initGesture () {listener = new listener) this);} public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {if (e1.getX ()-e2.getX ()> verticalMinDistance & Math. abs (velocityX)> minVelocity) {// switch Activity // Intent intent = new Intent (ViewSnsActivity. this, UpdateStatusActivity. class); // startActivity (intent); // Toast. makeText (this, "gesture to the left", Toast. LENGTH_SHORT ). show ();} else if (e2.getX ()-e1.getX ()> verticalMinDistance & Math. abs (velocityX)> minVelocity) {// switch Activity // Intent intent = new Intent (ViewSnsActivity. this, UpdateStatusActivity. class); // startActivity (intent); // Toast. makeText (this, "gesture to the right", Toast. LENGTH_SHORT ). show (); finish (); overridePendingTransition (R. anim. push_right_in, R. anim. push_right_out);} return false;} @ Override public void onLongPress (MotionEvent arg0) {// TODO Auto-generated method stub} @ Override public boolean onScroll (MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) {// TODO Auto-generated method stub return false;} @ Override public void onShowPress (MotionEvent arg0) {// TODO Auto-generated method stub} @ Override public boolean onSingleTapUp (MotionEvent arg0) {// TODO Auto-generated method stub return false ;} @ Override public boolean onTouch (View v, MotionEvent event) {// TODO Auto-generated method stub return mGestureDetector. onTouchEvent (event) ;}@ Override public boolean onDown (MotionEvent arg0) {// TODO Auto-generated method stub return false;} @ Override public boolean dispatchTouchEvent (MotionEvent ev) {mGestureDetector. onTouchEvent (ev); return super. dispatchTouchEvent (ev );}
How can multiple activities jump back and forth after a gesture sliding switch is attached ??
ViewPager + Fragment is used to replace all three activities A, B, and C with Fragment. N times have been used
In android, how does one implement a sliding activity? How does one slide left and right to implement activity switching?
Do you want to slide the activity or the page? If it is an activity, you can add a gesture to the current page, implement activity switching during sliding, and then add a switchover animation to the activity. If it is a qq effect, you can use a tab to do it, the implementation is very good, or activitygroup, you can also use fragment to do, these implementations are good. For page slide switching, you can use viewpager. This effect is very good. If the code is strong, you can use viewgroup scrolling to achieve the effect.