[期末系列]手把手教你自定义跳转效果,实现不一样的界面切换

在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的界面跳转,但还有需要完善的地方,代码也并非我原创,参数什么的都可以修改,努力修改出最完美的效果吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值