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>
网友评论