修改系统 activity 切换动画


修改 Android 切换动画

一、

activity 切换动画   

android:activityOpenEnterAnimation,
android:activityOpenExitAnimation,
android:activityCloseEnterAnimation
android:activityCloseExitAnimation

window dialog 动画  windowAnimation
android:windowEnterAnimation
android:windowExitAnimation

二、在项目中WindowAnimation的控制权大于Activity的控制权,
即在Activity转场过程中,如果同时设置了WindowAnimation和ActivityAnimation,
那么可能(因为这种情况非常多)只会执行WindowAnimation

三,源码修改activity动画

修改完成,单独编译frameworks/base/core/res/目录,push 新生成framework-res.apk

3.1将自己定义的anim文件放置frameworks/base/core/res/res/anim/目录,

3.2 修改 frameworks/base/core/res/res/values/styles

<style name="Animation.Activity">
新进
<item name="activityOpenEnterAnimation">@anim/activity_open_enter</item> 一个activity创建进入的效果。
旧出
<item name="activityOpenExitAnimation">@anim/activity_open_exit</item>   一个activity还没有finish()下退出效果, 比如有俩个activity A与B 首先启动A 然后再启动B
                                                                         那么A还没有finish()  这时A的退出效果
旧进
<item name="activityCloseEnterAnimation">@anim/activity_close_enter</item>

When closing the current activity, this is the animation that is run on the next activity (which is entering the screen).
表示上一个activity返回进入效果 比如有俩个activity A与B  B在最上面,B退出(finish)后 A重新进入的效果。

新出
<item name="activityCloseExitAnimation">@anim/activity_close_exit</item>  
When closing the current activity, this is the animation that is run on the current activity (which is exiting the screen).
表示的是activity finish()之后的效果 比如有俩个activity A与B B退出后会被finish() 那么B的退出效果在这定义。

---Task-- 动画
<item name="taskOpenEnterAnimation">@anim/task_open_enter</item>
When opening an activity in a new task, this is the animation that is run on the activity of the new task (which is entering the screen).

<item name="taskOpenExitAnimation">@anim/task_open_exit</item>
When opening an activity in a new task, this is the animation that is run on the activity of the old task (which is exiting the screen).

<item name="taskCloseEnterAnimation">@anim/task_close_enter</item>
When opening an activity in a new task, this is the animation that is run on the activity of the old task (which is exiting the screen).

<item name="taskCloseExitAnimation">@anim/task_close_exit</item>


<item name="taskToFrontEnterAnimation">@anim/task_open_enter</item>
<item name="taskToFrontExitAnimation">@anim/task_open_exit</item>


<item name="taskToBackEnterAnimation">@anim/task_close_enter</item>
When sending the current task to the background, this is the animation that is run on the top activity of the task behind it (which is entering the screen).

<item name="taskToBackExitAnimation">@anim/task_close_exit</item>

<item name="wallpaperOpenEnterAnimation">@anim/wallpaper_open_enter</item>
<item name="wallpaperOpenExitAnimation">@anim/wallpaper_open_exit</item>
<item name="wallpaperCloseEnterAnimation">@anim/wallpaper_close_enter</item>
</>

四、 在APP 层面的动画修改

4.1 对于WindowAnimation的定义很简单,在style.xml文件中只需要继承Animation Style即可

   <style name="Animation" parent="@android:style/Animation">
        <!--窗体进入动画-->
        <item name="android:windowEnterAnimation">@anim/slide_left_enter</item>
        <!--窗体退出动画-->
        <item name="android:windowExitAnimation">@anim/slide_right_exit</item>
    </style>

4.2 对于Activity,需要继承Animation Activity Style

<style name="AppTheme" parent="Theme.AppCompat.Light">
      <item name="android:windowAnimationStyle">@style/activityAnimationUpDown</item>
 </style>

<style name="activityAnimationUpDown" parent="@android:style/Animation.Activity">
    <item name="android:activityOpenEnterAnimation">@anim/in_from_left</item>
    <item name="android:activityOpenExitAnimation">@anim/out_from_right</item>
    <item name="android:activityCloseEnterAnimation">@anim/in_from_right</item>
    <item name="android:activityCloseExitAnimation">@anim/out_from_left</item>
</style>

 <activity
            android:name=".MainActivity"
            android:theme="@style/AppTheme" >
 </activity>



anim/out_from_right.xml
<?xml version="1.0" encoding="utf-8"?>

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXDelta="0"
    android:fromYDelta="0"
    android:toXDelta="100%p"
    android:toYDelta="0" >
</translate>

anim/in_from_left.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXDelta="-100%p"
    android:fromYDelta="0"
    android:toXDelta="0"
    android:toYDelta="0" >
</translate>

anim/out_from_left.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXDelta="0"
    android:fromYDelta="0"
    android:toXDelta="-100%p"
    android:toYDelta="0" >
</translate>

anim/in_from_right.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXDelta="100%p"
    android:fromYDelta="0"
    android:toXDelta="0"
    android:toYDelta="0" >
</translate>


或者 缩放透明的效果
zoomin.xml文件
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:Android="http://schemas.android.com/apk/res/android"
        Android:interpolator="@android:anim/decelerate_interpolator">
    <scale Android:fromXScale="2.0" android:toXScale="1.0"
           Android:fromYScale="2.0" android:toYScale="1.0"
           Android:pivotX="50%p" android:pivotY="50%p"
           Android:duration="@android:integer/config_mediumAnimTime" />
</set>

zoomout.xml文件
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:Android="http://schemas.android.com/apk/res/android"
        Android:interpolator="@android:anim/decelerate_interpolator"
        Android:zAdjustment="top">
    <scale Android:fromXScale="1.0" android:toXScale=".5"
           Android:fromYScale="1.0" android:toYScale=".5"
           Android:pivotX="50%p" android:pivotY="50%p"
           Android:duration="@android:integer/config_mediumAnimTime" />
    <alpha Android:fromAlpha="1.0" android:toAlpha="0"
            Android:duration="@android:integer/config_mediumAnimTime"/>
</set>  


猜你喜欢

转载自blog.csdn.net/kongbaidepao/article/details/80713091
今日推荐