Android Dialog 动画实例详解
动画描述: 动画与底部菜单一样出现和消失
制作过程:
1. 创建两个动画文件
window_in.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="0"
android:fromYDelta="1000"
android:toXDelta="0"
android:toYDelta="0" />
</set>
window_out.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="1000" />
</set>
2.将动画配置到style中:
<style name="main_menu_animstyle">
<item name="android:windowEnterAnimation">@anim/settingswindow_in_anim</item>
<item name="android:windowExitAnimation">@anim/settingswindow_out_anim</item>
</style>
3. 将动画应用于Dialog:
Window window = dialog.getWindow();
//设置显示动画
window.setWindowAnimations(R.style.main_menu_animstyle);
WindowManager.LayoutParams wl = window.getAttributes();
wl.x = 0;
wl.y = getWindowManager().getDefaultDisplay().getHeight();
//设置显示位置
dialog.onWindowAttributesChanged(wl);//设置点击外围解散
dialog.setCanceledOnTouchOutside(true);
dialog.show();
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章:Android 中从屏幕左下角弹出Dialog动画效果的实现代码