您的位置:首页 > 其它

【原创体验】Activity跳转页面切换漂亮效果

2010-12-30 12:43 274 查看
据我观察 默认的两个Activity 跳转的动画是 从左往右移动

在startActivity 后调用 overridePendingTransition(int enterAnim,int exitAnim),就可以实现Activity之间的动画,

其中enterAnim 是下一个Activity的enter动画效果,exitAnim 是当前Actitvity退出的动画效果

【注意只有Android的2.0(SdkVersion版本号为5)以后的版本才支持】 测试切换效果在创建项目的时候注意选择 Android版本

@Override

public void onClick(View v) {

Intent MyIntent = new Intent();

MyIntent.setClass(Activity02.this, Other.class);

Activity02.this.startActivity(MyIntent);

//默认的两个Activity 跳转的动画是 从左往右移动

//

下面是溶解效果

//

overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);

//

从左往右 快速移动

//

overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);

//

进入 缩放效果 退出 放大效果

overridePendingTransition(R.anim.zoomin,R.anim.zoomout);

}

注意缩放 放大效果是自定义的。上面两种切换效果是系统提供的。

zoomin.xml 和 zoomout.xml 要放在res//anim 文件夹下 所以要先新建anim文件夹

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=/"4.5/" android:toXScale=/"3.0/"

android:fromYScale=/"4.5/" android:toYScale=/"3.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>

其实切换的效果有很多 很炫 很酷 大家可以互相分享 增加用户体验.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: