1、首先先創建四個動畫文件 ①:left_in.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android
1、首先先創建四個動畫文件
①:left_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="600" android:fromXDelta="-100.0%p" android:toXDelta="0.0" /> </set>
②:left_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="600" android:fromXDelta="0.0" android:toXDelta="-100.0%p" /> </set>
③:right_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="600" android:fromXDelta="100.0%p" android:toXDelta="0.0" /> </set>
④:right_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="600" android:fromXDelta="0.0" android:toXDelta="100.0%p" /> </set>
2、在styles.xml里寫一個風格
<style name="MyTheme" parent="AppTheme"> <item name="android:windowAnimationStyle">@style/ActivityAnimation</item> </style> <style name="ActivityAnimation"> <item name="android:activityOpenEnterAnimation">@anim/slide_right_in</item> <item name="android:activityOpenExitAnimation">@anim/slide_left_out</item> <item name="android:activityCloseEnterAnimation">@anim/slide_left_in</item> <item name="android:activityCloseExitAnimation">@anim/slide_right_out</item> </style>
3、然後將AndroidManifest.xml文件裡面的<application>標簽的主題換成我們寫的就可以了