Enhanced implementation of Android activity Switching Effect

Source: Internet
Author: User

After finishing an application earlier, you need to add some effects.

Compared with applications on the iPhone, the most classic visual effect of interface switching is to zoom in and out.

Fortunately, Android has such an animation file.

As you know

Overridependingtransition ()

The simplest way to implement API.

------------------------

However, as mentioned on the Internet:

Note that the overridependingtransition function requires two ideas:
1. It must be called next to the startactivity () or finish () function.
2. It is applicable only to android2.0 and later versions.

----------------------------------------

The second point is not mentioned.

To mention the first point, this method must be called after the above two functions.

To put it simply, a --> B Switch

We can execute it after a is the startactivity method. What happens when a comes in?

For example, a is the entry activity.

Of course, the current application can easily solve this visual problem, because the application generally performs log or transitional activity.

Problem 1 is also basically solved.

However, I feel that this is written every time after the start or finish method.CodeVery troublesome

So I tried to write overridependingtransition in oncreate of the base class.

 
/*** @ Author Nono **/public abstract class baseactivity extends activity {public textview titleview; @ overrideprotected void oncreate (bundle savedinstancestate) {requestwindowfeature (window. feature_custom_title); super. oncreate (savedinstancestate); overridependingtransition (R. anim. zoomin, R. anim. zoomout );}

Yes .. Guess what happened behind this method.

Then I went to the overridependingtransition () method in the activity,

Then, the following nouns are used: activitymanagernative, activitymanagerproxy, and so on.

Introduce the activitymanager framework. Framework level. If you are interested, you can study it on Google.

Another method of switching effect is proposed.

Style File.

The above method seems to be able to solve the problem of switching.

However, you can see that there are only two statuses: startactivity, start, finish, and end.

At first, I considered the issue of activity singleton and non-destruction. That is, when it is not finished.

Unfortunately, no code is written.

For example, tablayout layout. A tabhost container has four activities. In general, when switching tags, we do not call finish, but only execute onstop, or even

The log found that it was only onpasue () (this problem is quite strange, and it is ignored for the moment ).

Finally, an Android: windowanimationstyle attribute under the style in the activity is found.

<Style name = "activty_fade_in_fade_out"> <item name = "@ Android: activityopenenteranimation"> @ anim/fade_in </item> <item name = "@ Android: activityopenexitanimation "> @ anim/fade_out </item> <item name =" @ Android: activitycloseenteranimation "> @ anim/fade_in </item> <item name =" @ Android: activitycloseexitanimation "> @ anim/fade_out </item> </style>

 
<Style name = "register_activity" parent = "xtheme"> <item name = "@ Android: windowanimationstyle"> @ style/activty_bottom_in_top_out </item> </style>

<Activity Android: Name = ". activity. loginactivity" Android: screenorientation = "portrait" Android: theme = "@ style/in_out_theme"/>

The above is only the style item can have more options, just to solve the problem mentioned above.

For more information about parameters, see

Http://developer.android.com/reference/android/R.styleable.html#WindowAnimation


By referring to the view effect on the interface, you can also customize the animation.

And in the layout File

Android: defines animation effects in layoutanimation.


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.