自定义dialog and anim

来源:互联网 发布:域名备案需要哪些资料 编辑:程序博客网 时间:2024/06/03 21:55
 button.setOnClickListener(new OnClickListener() {  

  1. @Override  
  2. public void onClick(View arg0) {  
  3.     // TODO Auto-generated method stub  
  4.     AlertDialog dialog = new AlertDialog.Builder(TestAndroid1Activity.this)  
  5.             .setTitle("title").setMessage("message").create();  
  6.     Window window = dialog.getWindow();  
  7.     window.setGravity(Gravity.BOTTOM);  //此处可以设置dialog显示的位置  
  8.         window.setWindowAnimations(R.style.mystyle);  //添加动画  
  9.     dialog.show();  
  10. }  
  11. );  

styles.xml

[java] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.   
  4.     <style name="mystyle" parent="android:Animation">  
  5.         <item name="@android:windowEnterAnimation">@anim/dialog_enter</item>  //进入时的动画  
  6.         <item name="@android:windowExitAnimation">@anim/dialog_exit</item>    //退出时的动画  
  7.     </style>  
  8. </resources>  


位于 res/anim/dialog_enter.xml

[java] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set xmlns:android="http://schemas.android.com/apk/res/android">  
  3.       
  4.     <translate  
  5.         android:fromYDelta="100%p"       %p指相对于父容器  
  6.         android:duration="600"  
  7.         />  
  8. </set>  


位于 res/anim/dialog_exit.xml

[java] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set xmlns:android="http://schemas.android.com/apk/res/android">  
  3.        
  4.       <translate  
  5.           android:toYDelta="100%p"  
  6.           android:duration="600"    //持续时间  
  7.           />  
  8. </set>  


此处只是做了垂直位移的效果,自己还可以试试别的效果。

<alpha />         透明度

<rotate />         旋转

<scale />        缩放

0 0
原创粉丝点击