Android 底部弹出Activity动画

第一步:创建

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);
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容