android - Control View size in AlertDialog -


i want create alertdialog dialogfragment title, ok button, cancel button , expandablelistview. problem expandablelistview takes space likes , pushes buttons , title out of dialog. want title @ top, buttons @ bottom , expandablelistview take rest of space, fullscreen, dialogfragment not increase/decrease in size when expanding it, rather keep scrollable.

here image describing situation, left 1 initialized dialogfragment, second after expanding 1 of sections of expandablelistview. nevermind ugliness.

expandablelistview expands much.

i achieve following:

  1. keep size of fragmentdialog fixed, preferably whole window (fill_parent/match_parent).
  2. keep buttons fixed @ bottom, title fixed @ top , expandablelistview fixed (but still scrollable) in center.

i have tried lots of various things, here current take.

the custom dialogfragment

public class recipefilterdialogfragment extends dialogfragment {      @override     public dialog oncreatedialog(bundle savedinstancestate) {          alertdialog.builder builder = new alertdialog.builder(getactivity());         builder.setmessage(r.string.recipe_filter_title);         builder.setpositivebutton(r.string.recipe_filter_button_ok, new dialoginterface.onclicklistener() {             public void onclick(dialoginterface dialog, int id) {                 // todo: perform filtering, fill list , return.             }         });         builder.setnegativebutton(r.string.recipe_filter_button_cancel, new dialoginterface.onclicklistener() {             public void onclick(dialoginterface dialog, int id) {                 // todo: kill dialog , return.             }         });          builder.setview(getactivity().getlayoutinflater().inflate(r.layout.recipe_filter_dialog, null));         builder.setcancelable(true);         return builder.create();     }      @override     public void onstart() {         super.onstart();         alertdialog dialog = (alertdialog) getdialog();         if (dialog != null)         {             int width = viewgroup.layoutparams.match_parent;             int height = viewgroup.layoutparams.match_parent;             //dialog.getwindow().setlayout(width, height);             dialog.getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen);         }     } } 

the xml file dialogfragment (recipe_filter_dialog.xml)

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >      <com.my.app.recipefilterexpandablelistview         android:id="@+id/recipe_filter_expandablelistview"         android:layout_width="fill_parent"         android:layout_height="fill_parent"     />  </linearlayout> 

the custom expandablelistview

public class recipefilterexpandablelistview extends expandablelistview {      public recipefilterexpandablelistview(context context, attributeset attrs)     {         super(context, attrs);         this.setongroupexpandlistener(new recipefilterdialogongroupexpandlistener(this));          // adapter fills expandablelistview, nevermind it.         this.setadapter(new recipefilterexpandablelistadapter(context, ((myactivity)context).getdbfilter()));     } } 

try set builder.settitle(r.string.recipe_filter_title); instead of builder.setmessage(r.string.recipe_filter_title); , decide height , width want dialog , set in onstart() method.

also try this:

constructor in dialog class:

 public recipefilterdialogfragment () {         setstyle(dialogfragment.style_no_frame, r.style.fullscreenstyle);     } 

and style dialog used above:

<style name="fullscreenstyle" parent="@android:style/theme.holo.light">     <item name="android:windowisfloating">false</item>     <item name="android:windowfullscreen">true</item> </style> 

also try use parent style dialog theme f.e:

<style name="fullscreenstyle" parent="@android:style/theme.holo.light.dialog"> 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -