Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Dialog Size Programmatically

In my program I create a dialog with the code below. Ideally I would like to scale the dialog by entering width and height parameter programmatically. Can anyone show me how to do this?

dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
popUpLayout = Globals.layoutInflater.inflate(R.layout.pop_up_layout, null);
dialog.setContentView(popUpLayout);
dialog.show();
like image 532
Ben Pearce Avatar asked Nov 07 '11 23:11

Ben Pearce


People also ask

How do I make alert dialog fill 90% of screen size?

According to Android platform developer Dianne Hackborn in this discussion group post, Dialogs set their Window's top level layout width and height to WRAP_CONTENT . To make the Dialog bigger, you can set those parameters to MATCH_PARENT . Demo code: AlertDialog.

How do I set margin to dialog in android programmatically?

getWindow(). getAttributes(); // change this to your dialog. params. y = -100; // Here is the param to set your dialog position.


1 Answers

Here is the code that ended up working:

dialog.getWindow().setLayout(275, 350);
like image 147
Ben Pearce Avatar answered Nov 04 '22 01:11

Ben Pearce