android对话框弹出方式动画
16lz
2021-01-23
android对话框弹出方式动画
button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub AlertDialog dialog = new AlertDialog.Builder(TestAndroid1Activity.this) .setTitle("title").setMessage("message").create(); Window window = dialog.getWindow(); window.setGravity(Gravity.BOTTOM); //此处可以设置dialog显示的位置 window.setWindowAnimations(R.style.mystyle); //添加动画 dialog.show(); } });
styles.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="mystyle" parent="android:Animation"> <item name="@android:windowEnterAnimation">@anim/dialog_enter</item> //进入时的动画 <item name="@android:windowExitAnimation">@anim/dialog_exit</item> //退出时的动画 </style> resources>
位于 res/anim/dialog_enter.xml<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="100%p" %p指相对于父容器 android:duration="600" /> </set>
位于 res/anim/dialog_exit.xml<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:toYDelta="100%p" android:duration="600" //持续时间 /> </set>
更多相关文章
- Android 中保存图片的代码
- Android 代码生成界面Sample
- Android 代码监控apk安装,卸载,替换
- 【Android】【动画】自定义插值器Interpolator
- android 滑动动画效果
- android 代码创建快捷方式
- DialogFragment设置自定义动画
- Android Recyclerview设置条目属性动画