您的位置:首页 > 其它

Activity之间切换的动画

2014-04-18 11:58 369 查看
void android.app.Activity.overridePendingTransition(int
enterAnim, int exitAnim)


public
void overridePendingTransition
(int enterAnim, int exitAnim)

Since: API
Level 5

Call immediately after one of the flavors of
startActivity(Intent)
or
finish()

to specify an explicit transition animation to perform next.

Parameters
enterAnimA resource ID of the animation resource to use for the incoming
activity. Use 0 for no animation.
exitAnimA resource ID of the animation resource to use for the outgoing
activity. Use 0 for no animation. 
-----------------------------------------------------------------------------------------------
在代码中,我们只需要实现如下:

Intent intent = new Intent();
intent.setClass(TestActivity.this,
MyActivity.class);
startActivity(intent);

overridePendingTransition(R.anim.in_from_right,
R.anim.out_to_left);//这里的enterAnim和exitAnim可以自己发挥

这两个resource
file是放在res目录下的anim目录中。下面写两个简单的animation:
-------------------------------in_from_right.xml-------------------------------------------

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

------------------------------------out_to_left.xml----------------------------------------

<?xml version="1.0"
encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
   
<translate android:fromXDelta="0%p"
android:toXDelta="-100%p"
   
    android:duration="500"
/>
</set>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: