欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Dialog底部弹出自定义view并且伴随动画弹出和消失

程序员文章站 2024-02-24 09:49:34
原图  点击后  代码 @override public void onclick(view view) { switc...

原图

Dialog底部弹出自定义view并且伴随动画弹出和消失

 点击后

Dialog底部弹出自定义view并且伴随动画弹出和消失

 代码

@override 
public void onclick(view view) { 
 switch (view.getid()) { 
  //加号逻辑 
  case r.id.iv_more: 
   alertdialog.builder builder = new android.app.alertdialog.builder(this,r.style.remind_dialog); 
   layoutinflater inflater = layoutinflater.from(this); 
   view minflate = inflater.inflate(r.layout.activity_plus, null); 
   iv_dialog_cacle = (imageview) minflate.findviewbyid(r.id.iv_cancel); 
   iv_dialog_cacle.setonclicklistener(new view.onclicklistener() { 
    @override 
    public void onclick(view v) { 
     dialog.dismiss(); 
    } 
   }); 
   dialog = builder.create(); 
   dialog.show(); 
   window window = dialog.getwindow(); 
   window.setgravity(gravity.bottom); 
   window.setwindowanimations(r.style.showdialog); 
   window.setcontentview(minflate); 
   windowmanager windowmanager = getwindowmanager(); 
   display display = windowmanager.getdefaultdisplay(); 
   windowmanager.layoutparams lp= dialog.getwindow().getattributes(); 
   lp.width = (int)(display.getwidth()); //设置宽度 
   dialog.getwindow().setattributes(lp); 
   break; 
 } 
} 

remind_dialog

<style name="remind_dialog" parent="@android:style/theme.dialog"> 
 <item name="android:windowframe">@null</item> 
 <item name="android:windowisfloating">true</item> 
 <item name="android:windowistranslucent">false</item> 
 <item name="android:windownotitle">true</item> 
 <item name="android:background">@android:color/transparent</item> 
 <item name="android:windowbackground">@android:color/transparent</item> 
 <item name="android:backgrounddimenabled">true</item> 
 <item name="android:windowanimationstyle">@null</item> 
 <item name="android:windowfullscreen">true</item> 
</style> 

showdialog

<style name="showdialog" > 
   <item name="@android:windowenteranimation">@anim/dialog_enter</item> 
  <item name="@android:windowexitanimation">@anim/dialog_exit</item> 
 </style> 

dialog_enter

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 
 <translate 
  android:duration="200" 
  android:toydelta="0%" 
  android:fillafter="true" 
  android:fromydelta="100%p" /> 
</set> 

dialog_exit

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 
 <translate 
  android:duration="200" 
  android:fromydelta="0%" 
  android:fillafter="true" 
  android:toydelta="100%p" /> 
</set> 

以上所述是小编给大家介绍的dialog底部弹出自定义view并且伴随动画弹出和消失,希望对大家有所帮助