实现类似微信的activity切换动画
1、首先定义4个动画文件。
slide_left_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300" android:fromXDelta="-100%p" android:toXDelta="0" /> </set>
slide_left_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300" android:fromXDelta="0" android:toXDelta="-100%p" /> </set>
slide_right_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300" android:fromXDelta="100%p" android:toXDelta="0" /> </set>
slide_right_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300" android:fromXDelta="0" android:toXDelta="100%p" /> </set>
2、定义一个style
<style name="activityAnimation" parent="@android:style/Animation"> <item name="android:activityOpenEnterAnimation">@anim/a_slide_right_in</item> <item name="android:activityOpenExitAnimation">@anim/a_slide_left_out</item> <item name="android:activityCloseEnterAnimation">@anim/a_slide_left_in</item> <item name="android:activityCloseExitAnimation">@anim/a_slide_right_out</item> </style>
3、把定义的style放到AppTheme里边
<style name="AppTheme" parent="AppBaseTheme"> <item name="android:windowAnimationStyle">@style/activityAnimation</item> </style>
4、在AndroidManifest.xml里边设置application的theme
<application android:name=".App" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > </application>
相关推荐
xjp 2020-05-28
fengyeezju 2020-01-11
xilove0 2020-01-10
ALiDan 2019-12-16
JunkChen 2011-09-15
dingguagua 2013-07-23
缘来如此 2013-08-30
lihaoxiang 2019-11-14
Andrew的杂记 2010-10-07
luoj 2011-01-28
满城风絮 2011-09-09
doyouhaveIET 2011-08-31
Mexican 2011-08-31
Rgenxiao 2011-08-29
kangtingting0 2011-08-29
luoj 2011-08-23
西木 2011-08-17