现在的位置: 首页 > 综合 > 正文

android 动画切换效果

2018年01月31日 ⁄ 综合 ⁄ 共 2154字 ⁄ 字号 评论关闭

一:整个app都采用淡入淡出效果

1:在anim文件夹下定义动画文件

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:定义styles.xml文件

<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.在配置文件下配置主题

<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>

二:单个页面采用淡入淡出效果

在anim文件夹下定义动画文件(同上),然后在Actiivty中finish()或startActivity()后加一下代码:

<span style="font-size:14px;">overridePendingTransition(R.anim.fade_in, R.anim.fade_out);</span>

抱歉!评论已关闭.