美文网首页
Android 底部弹出Activity动画

Android 底部弹出Activity动画

作者: 大白520 | 来源:发表于2020-03-13 23:15 被阅读0次

第一步:创建

res目录下创建anim文件夹(如果没有的话)
anim文件夹下创建三个文件:

  1. bottom_in.xml(A页面底部弹入动画)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="300"
        android:fromYDelta="100%p"
        android:toYDelta="0" />
</set>
  1. bottom_out.xml(B页面关闭弹出动画)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="300"
        android:fromYDelta="0"
        android:toYDelta="100%p" />
</set>
  1. bottom_silent.xml (静止动画)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromYDelta="0"
        android:toYDelta="0"
        android:duration="300"
    />
    <!-- (注意这里的时间要比上面两个的长,否则会出现黑色背景)-->
</set>

第二步:设置

  1. 第一个 Activity 通过 Intent 意图打开第二个新 Activity 的弹出动画设置:
    startActivity 后添加 overridePendingTransition(R.anim.bottom_in,R.anim.bottom_silent) 方法
Intent intent = new Intent(this, BActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
overridePendingTransition(R.anim.bottom_in,R.anim.bottom_silent);
  1. 新 Activity 被关闭返回第一个 Activity 的退出动画设置:
    重写finish()
@Override
public void finish() {
    super.finish();
    overridePendingTransition(R.anim.bottom_silent,R.anim.bottom_out);
}

相关文章

网友评论

      本文标题:Android 底部弹出Activity动画

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