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>
将动画配置到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>
将动画应用于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();
我是天王盖地虎的分割线
可以参考github:https://github.com/pinguo-yuyidong/Study_Demos/tree/master/BottomMenu
时间: 2025-01-04 19:28:22