在Android Studio中,一般如果没有特别设置的话,界面切换特效都是千篇一律的,很枯燥,而且有时候这种特效和我们本身App的风格很不符合,如果给用户使用的话,那感觉是大打折扣的,那么,我们该如何自定义界面切换效果呢?下面我将以实现类似iphone跳转页面特效为例,自定义我们App自己的界面切换特效。
首先,在res文件夹下,新建一个文件夹,建议取名为anim,在该文件夹中新建两个xml文件。
zoomin.xml的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Android="http://schemas.android.com/tools"
Android:interpolator="@android:anim/decelerate_interpolator">
<scale Android:fromXScale="1.0" android:toXScale="1.0"
Android:fromYScale="1.0" android:toYScale="1.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"
xmlns:Android="http://schemas.android.com/tools"
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>
好的,到这里基本已经完成了,下面我们到相应的地方去调用就可以了,调用的语句为:
// 实现类似iphone的跳转页面效果
overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
需要注意的一点是,该语句需要放在实现跳转语句的后面,例如我是这么调用的:
Intent intent = new Intent(HomePage.this, AccountPage.class);
//跳转页面
startActivity(intent);
// 实现类似iphone的跳转页面效果
overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
运行程序,你就会发现界面跳转变得类似于iphone的界面跳转,但还有需要完善的地方,代码也并非我原创,参数什么的都可以修改,努力修改出最完美的效果吧!