设置activity打开关闭动画——左右滑入滑出

来源:互联网 发布:在win7下安装ubuntu 编辑:程序博客网 时间:2024/05/23 02:04

res/anim中文件:


(1)in_left
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate android:interpolator="@android:anim/accelerate_interpolator" android:duration="500" android:fillAfter="true" android:fromXDelta="-100%p" android:toXDelta="0"/></set>



(2)in_right
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate android:interpolator="@android:anim/accelerate_interpolator" android:duration="500" android:fillAfter="true" android:fromXDelta="100%p" android:toXDelta="0"/></set>



(3)out_left
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate android:interpolator="@android:anim/accelerate_interpolator" android:duration="500" android:fillAfter="true" android:fromXDelta="0" android:toXDelta="-100%p"/></set>



(4)out_right
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate android:interpolator="@android:anim/accelerate_interpolator" android:duration="500" android:fillAfter="true" android:fromXDelta="0" android:toXDelta="100%p"/></set>



方法一:

(1)在startActivity后,finish前添加overridePendingTransition(R.anim.in_right, R.anim.out_left); 

(2)关闭时在finish后添加overridePendingTransition(R.anim.in_left, R.anim.out_right); 


方法二:

(1)配置AndroidMainfest.xm.文件

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"

        android:theme="@style/AppTheme" >


(2)修改theme,即styles.xml中AppTheme
<style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <!-- 设置activity切换动画 --> 
        <item name="android:windowAnimationStyle">@style/activityAnimation</item>

    </style>


(3)编写样式activityAnimation
<style name="activityAnimation" parent="@android:style/Animation">
        <item name="android:activityOpenEnterAnimation">@anim/in_right</item>
  <item name="android:activityOpenExitAnimation">@anim/out_left</item>
<item name="android:activityCloseEnterAnimation">@anim/in_left</item>
<item name="android:activityCloseExitAnimation">@anim/out_right</item>
</style>


ok!结束
0 0
原创粉丝点击