Android Animation Toggle Effect

Source: Internet
Author: User

One: The entire app has fade effect 1: Define an animation file under the Anim folder

Accelerate_interpolator.xml

<span style= "FONT-SIZE:14PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><accelerateinterpolator/></span>
Decelerate_interpolator.xml
<span style= "FONT-SIZE:14PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><decelerateinterpolator/></span>

Fade_in.xml

<span style= "FONT-SIZE:14PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><alpha xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:duration=" @android: Integer/config_longanimtime "    android:fromalpha=" 0.0 "    android: Interpolator= "@anim/decelerate_interpolator"    android:toalpha= "1.0"/></span>
Fade_out.xml

<span style= "FONT-SIZE:14PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><alpha xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:duration=" @android: Integer/config_mediumanimtime "    android:fromalpha=" 1.0 "    Android : interpolator= "@anim/accelerate_interpolator"    android:toalpha= "0.0"/></span>

2: Define Styles.xml file

<span style= "FONT-SIZE:14PX;" ><resources xmlns:android= "Http://schemas.android.com/apk/res/android" >    <style name= " Appbasetheme "parent=" Android:Theme.Light "></style>    <style name=" Apptheme "parent=" Appbasetheme " >        <item name= "Android:windowanimationstyle" > @style/myanimation</item>    </style>    <style name= "myanimation" parent= "@android: style/animation.activity" >        <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 ></resources></span>

3. Configure the theme under configuration files
<span style= "FONT-SIZE:14PX;" ><application        android:allowbackup= "true"        android:icon= "@drawable/ic_launcher"        android:label= "@string/app_name"        android:theme= "@style/apptheme" >        <activity            android:name= " Com.union.foodunion.WelcomeActivity "            android:label=" @string/app_name ">            <intent-filter>                <action android:name= "Android.intent.action.MAIN"/>                <category android:name= " Android.intent.category.LAUNCHER "/>            </intent-filter>        </activity></application> </span>
Two: single page with fade effectdefine the animation file under the Anim folder (IBID.), then add the code after finish () or startactivity () in actiivty:

<span style= "FONT-SIZE:14PX;" >overridependingtransition (r.anim.fade_in, R.anim.fade_out);</span>


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.