Sliding left in Activity to return listening

Source: Internet
Author: User
Tags gety

NetEase News has a cool effect. It also has this effect when QQ enters the chat interface, that is, when sliding from the left side of the interface to the right side, the interface exits, in fact, the function is easy to implement:

1)

Implement implements OnTouchListener by Activity

 

2) implement the onTouch method:

/**
* Sliding left to return listening
*/
@ Override
Public boolean onTouch (View v, MotionEvent event ){
Switch (event. getAction ()){
Case MotionEvent. ACTION_DOWN:
StartX = event. getX ();
StartY = event. getY ();
Break;
Case MotionEvent. ACTION_UP:
Float endX = event. getX ();
Float endY = event. getY ();
If (Math. abs (endX-startX)> 150 & (endY-startY) = 0 | Math. abs (endX-startX)/(endY-startY)> 2 )){
Finish ();
}
Break;
Default:
Break;
}
Return false;
}

 

Sliding left in Activity to return listening

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.