DialogFragment's Width Takes The Whole Screen Unlike AlertDialog
Solution 1:
If you are planning to run this application on a fixed size devices than it is ok, but if your application will run on different size devices (phones of different screen sizes or tablets) than consider applying match_parent on your fragment container, and apply layout padding from parent container with the proportion of empty space you need to surround your fragment.
This will let you control the size of your fragment and at the same time will allow smooth resizing in case of different screen sizes.
For example, if you inflate your activity layout from XML file that contains linear layout root element and a fragment child element, the padding is applied on linear layout element and the match_parent will be for the fragment element. in such case you choose a relevant padding figures that will let you achieve your targets.
I hope this provide some useful implementation ideas to you.
Solution 2:
try what worked by me:
my class is extends AlertDialog instead of DialogFragment,
and inside the class I override show function as follows:
@Override
public void show() {
super.show();
getWindow().setLayout(500, 300);
and then i open it like this:
MyDialog myDialog = new MyDialog(getActivity());
myDialog.show();
hope it helps!
Solution 3:
this is what I did, I just set the DialogFragment's width to 520 & it gave me exactly what I wanted :)
Post a Comment for "DialogFragment's Width Takes The Whole Screen Unlike AlertDialog"