Android activity切换动画overridePendingTransition
overridePendingTransition
在startActivity()或finish()后,调用overridePendingTransition(R.anim.**in,R.anim.**out)方法.
- 一)实现淡入淡出的效果如下:
startActivity(new Intent(SplashActivity.this, MainActivity.class));
overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
SplashActivity.this.finish();
- 二)由左向右滑入的效果改变一下参数即可
overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
- 三)要实现zoomin和zoomout,即类似iphone的进入和退出时的效果
在res目录下新建文件夹anim,然后在anim下新建两个xml,默认选项不用更改,分别命名为zoomin.xml和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" > <scale android:duration="@android:integer/config_mediumAnimTime" android:fromXScale="2.0" android:fromYScale="2.0" android:pivotX="50%p" android:pivotY="50%p" android:toXScale="1.0" android:toYScale="1.0" /> </set>
<?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:duration="@android:integer/config_mediumAnimTime" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%p" android:pivotY="50%p" android:toXScale=".5" android:toYScale=".5" /> <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="1.0" android:toAlpha="0" /> </set>