当前位置: 代码迷 >> Android >> android会话弹出框动画
  详细解决方案

android会话弹出框动画

热度:128   发布时间:2016-04-28 01:44:28.0
android对话弹出框动画
  1. 转自:http://blog.csdn.net/wangjia55/article/details/12975255
  2. //自定义Dialog??
  3. ????class?myDialog?extends?Dialog{??
  4. ??????????
  5. ????????private?Window?window?=?null;??
  6. ??????????
  7. ????????public?myDialog(Context?context)??
  8. ????????{??
  9. ????????????super(context);??
  10. ????????}??
  11. ??????????
  12. ????????public?void?showDialog(int?layoutResID,?int?x,?int?y){??
  13. ????????????setContentView(layoutResID);??
  14. ??????????????
  15. ????????????windowDeploy(x,?y);??
  16. ??????????????
  17. ????????????//设置触摸对话框意外的地方取消对话框??
  18. ????????????setCanceledOnTouchOutside(true);??
  19. ????????????show();??
  20. ????????}??
  21. ??????????
  22. ????????//设置窗口显示??
  23. ????????public?void?windowDeploy(int?x,?int?y){??
  24. ????????????window?=?getWindow();?//得到对话框??
  25. ????????????window.setWindowAnimations(R.style.dialogWindowAnim);?//设置窗口弹出动画??
  26. ????????????window.setBackgroundDrawableResource(R.color.vifrification);?//设置对话框背景为透明??
  27. ????????????WindowManager.LayoutParams?wl?=?window.getAttributes();??
  28. ????????????//根据x,y坐标设置窗口需要显示的位置??
  29. ????????????wl.x?=?x;?//x小于0左移,大于0右移??
  30. ????????????wl.y?=?y;?//y小于0上移,大于0下移????
  31. //????????????wl.alpha?=?0.6f;?//设置透明度??
  32. //????????????wl.gravity?=?Gravity.BOTTOM;?//设置重力??
  33. ????????????window.setAttributes(wl);??
  34. ????????}??
  35. ????}??
  36. }??
  37. ???
  38. ???
  39. 设置窗口弹出,退出动画在res/values下创建style??
  40. <?xml?version="1.0"?encoding="utf-8"?>??
  41. <!--?设置dialog弹出,退出动画?-->??
  42. ??
  43. <resources>??
  44. ????<style?name="dialogWindowAnim"?parent="android:Animation"?mce_bogus="1">??
  45. ????????<item?name="android:windowEnterAnimation">@anim/dialog_enter_anim</item>??
  46. ????????<item?name="android:windowExitAnimation">@anim/dialog_exit_anim</item>??
  47. ????</style>??
  48. ??????
  49. </resources>??
  50. ???
  51. 在res/anim下创建,设置dialog窗口弹出动画??
  52. <?xml?version="1.0"?encoding="utf-8"?>??
  53. ??
  54. <!--?弹出时动画?-->??
  55. <set?xmlns:android="http://schemas.android.com/apk/res/android">??
  56. ????<scale???
  57. ????????android:interpolator="@android:anim/accelerate_interpolator"??
  58. ????????android:fromXScale="1.0"??
  59. ????????android:toXScale="1.0"??
  60. ????????android:fromYScale="0.0"??
  61. ????????android:toYScale="1.0"??
  62. ????????android:pivotX="0%"??
  63. ????????android:pivotY="100%"??
  64. ????????android:fillAfter="false"??
  65. ????????android:duration="400"/>??
  66. </set>??
  67. ???
  68. 在res/anim下创建,设置dialog窗口退出动画??
  69. <?xml?version="1.0"?encoding="utf-8"?>??
  70. <!--?退出时动画效果?-->??
  71. <set?xmlns:android="http://schemas.android.com/apk/res/android">??
  72. ????<scale???
  73. ????????android:interpolator="@android:anim/accelerate_interpolator"??
  74. ????????android:fromXScale="1.0"??
  75. ????????android:toXScale="1.0"??
  76. ????????android:fromYScale="1.0"??
  77. ????????android:toYScale="0.0"??
  78. ????????android:pivotX="0%"??
  79. ????????android:pivotY="100%"??
  80. ????????android:fillAfter="false"??
  81. ????????android:duration="400"/>??
  82. </set>??
  83. ???
  84. 在res/values下创建color??
  85. <?xml?version="1.0"?encoding="utf-8"?>??
  86. <resources>??
  87. ????<color?name="vifrification">#00000000</color>???<!--?透明?-->??
  88. </resources> ?
  相关解决方案