android过渡动画

示例

从左往右渐入渐出

实现

一 在style文件中新建动画样式

XML 复制代码
    <!-- 定义动画样式 -->
    <style name="FullScreenDialogAnimation">
        <!-- 打开时动画 -->
        <item name="android:windowEnterAnimation">@anim/slide_in_right</item>
        <!-- 关闭时动画 -->
        <item name="android:windowExitAnimation">@anim/slide_out_left</item>
    </style>
XML 复制代码
<!-- slide_out_left.xml -->
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0"
        android:toXDelta="100%p"
        android:duration="300" />
</set>
XML 复制代码
<!-- slide_in_right.xml -->
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="100%p"
        android:toXDelta="0"
        android:duration="300" />
</set>

二 在需要使用的地方调用这个style即可

java 复制代码
Dialog dialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.setContentView(R.layout.dialog_fullscreen);

// 设置进入动画
dialog.getWindow().setWindowAnimations(R.style.FullScreenDialogAnimation);

// 显示Dialog
dialog.show();
相关推荐
Joren的学习记录1 天前
【Linux运维大神系列】docker详解(四)
linux·运维·docker
利剑 -~1 天前
mysql面试题整理
android·数据库·mysql
Elastic 中国社区官方博客1 天前
让我们把这个 expense 工具从 n8n 迁移到 Elastic One Workflow
大数据·运维·elasticsearch·搜索引擎·ai·信息可视化·全文检索
( •̀∀•́ )9201 天前
GitHub Actions SSH 部署密钥
运维·ssh·github
louqle1 天前
docker基本知识及常用命令汇总
运维·docker·容器
梁同学与Android1 天前
Android ---【经验篇】ArrayList vs CopyOnWriteArrayList 核心区别,怎么选择?
android·java·开发语言
学烹饪的小胡桃1 天前
【运维学习】实时性能监控工具 WGCLOUD v3.6.2 更新介绍
linux·运维·服务器·学习·工单系统
叫致寒吧1 天前
Docker
运维·docker·容器
沐怡旸1 天前
【翻译】adb screenrecord 帮助文档
android
白露与泡影1 天前
使用systemd,把服务装进 Linux 心脏里~
linux·运维·python