Android中关于Dialog滑动弹出的简单动画的设置
2016-06-19 01:19
567 查看
弹出位置–>>> 屏幕中间
1.通过代码设置Dialog//获取当前布局的Window Window window = getWindow(); //设置无标题栏 window.requestFeature(Window.FEATURE_NO_TITLE); //背景为透明 window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //设置Dialog的布局 setContentView(R.layout.dialog_common); WindowManager.LayoutParams params = window.getAttributes(); //显示隐藏的动画效果 params.windowAnimations = R.style.MyDialogAnimationCenter; params.gravity = Gravity.CENTER; //位置在屏幕处于居中位置
2.设置动画效果
<!-- Dialog从center弹出的动画效果--> <style name="MyDialogAnimationCenter" > <item name="android:windowEnterAnimation">@anim/dialog_bottom_center_enter</item> <item name="android:windowExitAnimation">@anim/dialog_bottom_center_exit</item> </style>
3.设置动画属性(创建于res\anim)
--->> dialog_bottom_center_enter.xml文件 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="300" android:fromYDelta="-200%" android:toYDelta="0"/> <alpha android:duration="200" android:fromAlpha="0" android:toAlpha="1" android:interpolator="@android:interpolator/linear"/> </set> --->>dialog_bottom_center_exit.xml文件 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="300" android:fromYDelta="0%" android:toYDelta="200%"/> <alpha android:duration="300" android:fromAlpha="1" android:toAlpha="0" android:interpolator="@android:interpolator/linear"/> </set>
弹出位置–>>> 屏幕底部
1.通过代码设置Dialog//获取当前布局的Window Window window = getWindow(); //设置无标题栏 window.requestFeature(Window.FEATURE_NO_TITLE); //背景为透明 window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); // 设置Dialog的布局 setContentView(R.layout.dialog_usercenter_edit_sex); WindowManager.LayoutParams params = window.getAttributes(); //位置在屏幕处于底部位置 params.gravity = Gravity.BOTTOM; //显示隐藏的动画效果 params.windowAnimations = R.style.MyDialogAnimation;
2.设置动画效果(创建于values\styles文件)
<!-- Dialog从底部弹出的动画效果--> <style name="MyDialogAnimation" > <item name="android:windowEnterAnimation">@anim/dialog_bottom_center_enter</item> <item name="android:windowExitAnimation">@anim/dialog_bottom_center_exit</item> </style>
3.设置动画属性
--->> dialog_bottom_enter.xml文件 <?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromYDelta="100%" android:toYDelta="0" > </translate> --->> dialog_bottom_exit.xml文件 <?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromYDelta="0" android:toYDelta="100%" > </translate>
相关文章推荐
- Android嵌套滑动控件的冲突解决和ViewPager适配当前子控件高度不留空白的办法
- Android include标签的监听事件处理
- Android:Intent
- Android将手机相册图片展示到GridView中
- Android消息机制的原理剖析—闭环总结
- android字符串+数字变量方法之%1$s、%1$d的用法
- Android:menu的使用
- Android简易实战教程--第一话《最简单的计算器》
- Android简易实战教程--第一话《最简单的计算器》
- Android6邪门了,刷机神器TWRP居然在重启动之后消失了,可我没有重装系统啊。
- 解决android - No view found for id 0xxxxxxxx等问题
- Android 采用post方式提交数据到服务器
- Android 之dragger使用
- Android 之dragger使用
- Android 之dragger使用
- Android 开源框架ImageLoader完全解析(一)--- 基本介绍及使用
- github项目解析(五)-->android日志框架
- Android设置全屏
- 致Android-那些年,我们一起踩过的坑
- Rxjava + retrofit + dagger2 + mvp搭建Android框架