Android imitation wechat sliding exit activity

design sketch:

Principle:

The principle can be described clearly in one sentence. Rewrite the dispatchtouchevent of the activity. When sliding, get the contentview of the last activity at the top of the stack in the activity stack and add it to the decorview of the activity at the top of the stack. During the sliding process, pan the view. After sliding, return the contentview used in the previous step to the previous activity, and then finish the current activity.

ActivityStack:

Implement the application.activitylifecyclecallbacks interface, register this stack in the app's application, and call back the methods in the interface when the activity in the app is added or deleted.

Then register the implementation class in the application

DecorView:

1. Decorview is the topmost view of the entire window interface

2. Decorview has only one child view, LinearLayout, which represents the entire window interface, including notification bar, title bar, and content area.

3. Get decorview: activity. Getwindow(). Getdecorview()

slide:

Rewrite the dispatchtouchevent of an activity and set a threshold value. When starting within the threshold value, get the contentview of the previous activity and add it to the current decorview. The index is 0 and set it to the lowest value. During the sliding process, the x value of the container is dynamically changed to make the translation effect. After releasing the hand, cancel or close the animation. After the animation, return the contentview you got earlier.

DEMO:

https://github.com/gumingwei/SwipeBackActivity

The above is the Android imitation wechat sliding exit activity introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>