android开发设置Dialog出现消失动画

时间:2022-11-01 20:41:18

Dialog弹出或者消失时添加动画效果

res文件下新建文件夹 anim

dialog_in进入动画
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromYDelta="100%"
android:toYDelta="0" />
dialog_out对话框消失时动画
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="200"    android:fromYDelta="0"    android:toYDelta="100%" /> 

xml中设置Dialog style风格

<style name="appupdate_dialog" parent="@android:style/Theme.Dialog">           <!-- dialog进入退出动画 -->        <item name="android:windowAnimationStyle">@style/DialogAnimation</item> </style> // <!-- dialog进入退出动画 -->    <style name="dialogAnimation" parent="@android:style/Animation.Dialog">        <item name="android:windowEnterAnimation">@anim/dialog_in</item>        <item name="android:windowExitAnimation">@anim/dialog_out</item>    </style>
dia = new Dialog(context, R.style.dialogAnimation);
Window window = dia.getWindow();
window.setWindowAnimations(R.style.ad_dialog);