Android imitation wechat right slide return function example code
•
Android
First, the renderings are as follows:
First, analyze the main technical points of the function. Right sliding is gesture judgment. Return is executed only when sliding to the full distance, and the position of finger pressing is on the far left of the screen (this also has a certain range). These can be realized by ontouchevent. Then there is the sliding effect when returning. Obviously, this is realized by the acitivty switching animation. All right, let's start after the analysis. The following code is:
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()){ case MotionEvent.ACTION_DOWN: x=event.getX(); y=event.getY(); // Log.e("ACTION_DOWN","x="+x); break; case MotionEvent.ACTION_MOVE: float mX = event.getX(); float mY = event.getY(); float dX = Math.abs(mX-x); float dY = Math.abs(mY-y); scollX = mX-x; if (isScroll && scollX>0){ view.scrollTo(-(int) scollX,0); } break; case MotionEvent.ACTION_UP: if (isScroll && scollX>300){ finish(); overridePendingTransition(R.anim.bga_sbl_activity_backward_enter,R.anim.bga_sbl_activity_backward_exit); }else { isScroll = false; view.scrollTo(0,0); } break; } return false; }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码