Activity切换动画

作者: hahauha | 来源:发表于2019-01-24 17:29 被阅读0次

Activity切换动画

方式一:overridePendingTransition()

示例动画:如图右上角一点展开切入,退出时收回右上角


image.png

1、入场动画right_top_expend_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false"
    android:zAdjustment="top">
    <scale
        android:fromXScale="0.0"
        android:toXScale="1.0"
        android:fromYScale="0.0"
        android:toYScale="1.0"
        android:pivotX="95%"
        android:pivotY="5%"
        android:duration="500"
        />
</set>

2、退场动画right_top_pack_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false"
    android:zAdjustment="top">
    <scale
        android:fromXScale="1.0"
        android:toXScale="0.0"
        android:fromYScale="1.0"
        android:toYScale="0.0"
        android:pivotX="95%"
        android:pivotY="5%"
        android:duration="500"
        />
</set>

3、使用
onCreate() 中

overridePendingTransition(R.anim.right_top_expend_in, R.anim.activity_stay);

finish()中,必须重写finish()方法,在finish()之后设置

@Override
public void finish() {
     super.finish();
     overridePendingTransition(0, R.anim.right_top_pack_out);
}

4、注意:R.anim.activity_stay 设置这个是解决切换时黑屏问题,代码如下

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="500"
        android:fromAlpha="1"
        android:toAlpha="1" />
</set>

相关文章

网友评论

    本文标题:Activity切换动画

    本文链接:https://www.haomeiwen.com/subject/mbrujqtx.html