AndroidのActivity之回顾跳转动画

转自:http://www.cnblogs.com/bvin/archive/2012/12/08/2808338.html

================================================================================

(activityOpenExitAnimation),将要出现的画面进来(activityOpenEnterAnimation),当前的页面在后层,下一个页面在前层

第二步:进入了第二个页面按返回键:当前的页面隐退(activityCloseEnterAnimation),之前的页面进来(activityCloseExitAnimation),当前的页面在后层,前一个页面在前层

定义好了这四个动画之后,需要定义一个继承至android:style/Animation.Activity的风格,而这个风格还不能直接应用在activity上,因为这些动画要生成在windowAnimationStyle才可以应用在Activity主题上

看style.xml风格文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    
    <style mce_bogus="1" name="ThemeActivity">
        <item name="android:windowAnimationStyle">@style/AnimationActivity</item>
         <item name="android:windowNoTitle">true</item>
    </style>
    
    <style name="AnimationActivity" parent="@android:style/Animation.Activity" mce_bogus="1">
        <item name="android:activityOpenEnterAnimation">@anim/open_enter</item>
         <item name="android:activityOpenExitAnimation">@anim/open_exit</item>
          <item name="android:activityCloseEnterAnimation">@anim/close_enter</item>
           <item name="android:activityCloseExitAnimation">@anim/close_exit</item>
    </style>
    
</resources>

要再看看anim.xml动画文件么?

open_enter.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    
   <translate android:fromYDelta="-100%" android:toYDelta="0" android:duration="1000" />
   <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000"/>

</set>

open_exit.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    
     <translate android:fromYDelta="0" android:toYDelta="100%" android:duration="1000" />
     <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="1000"/>
</set>

close_enter.xml:

<?xml version="1.0" encoding="utf-8"?>
<set  xmlns:android="http://schemas.android.com/apk/res/android">
   <translate android:fromXDelta="-100%" android:toXDelta="0" android:duration="1000"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000"/>
</set>

close_exit.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0" android:toXDelta="100%" android:duration="1000"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="1000"/>

然后看menifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cn.com.bvin.demo.anim"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
       <!--  android:theme="@style/ThemeActivity" 将应用于所有Activity -->
       
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/ThemeActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".NextActivity" 
            android:theme="@style/ThemeActivity">
             <!--  android:theme="@style/ThemeActivity" 用于当前Activity -->
        </activity>
    </application>

</manifest>
posted @ 2013-02-22 22:37  __木头鱼__  阅读(372)  评论(0编辑  收藏  举报