1
I have a very simple registration form that appears when you click a sign up button. This form appears in a DialogFragment
, however, with a very small size.
Zoning on the internet I found a code that changes the size of it:
@Override
public void onStart() {
super.onStart();
if (getDialog() == null)
return;
int dialogWidth = 200;
int dialogHeight = 400;
getDialog().getWindow().setLayout(dialogWidth, dialogHeight);
}
But apparently he sets these values in pixels, so I wanted to know if there is a way to calculate the width of the screen (or view I don’t know) and set the width at 80% of the screen and let the height increase automatically.
Note: I know it’s a bit confused my words but I can understand my goal with this question, in case I didn’t understand just make a comment that I explain in more detail.
Width worked but then it’s mandatory to put height, and I wanted it to automatically increase height (something like wrap_parent).
– Bruno Romualdo
And in line . getSystemService the android studio shows the non-static error method getSystemService(String) cannot be referenced from a Static context
– Bruno Romualdo
I adjusted the code above, with respect to height, would change based on some event?
– Geferson
No, I have a registration form with a title Register, and a Textview and Edittext for the fields Name, Login, Password and Repeat Password, plus two buttons one to cancel the registration and another to register.
– Bruno Romualdo
So the width has to be 80% of the screen but the height has to increase by itself. I would have some idea of how to do this?
– Bruno Romualdo
So the height of the dialog would have to be the sum of the components inside it? Something like that?
– Geferson
Exactly, just like when we set the height of a layout with wrap_parent.
– Bruno Romualdo
When you mount the dialog, you inflate it from a view? you can set the height straight in the view. Post the dialog code to take a look.
– Geferson
My man, I can’t believe I didn’t do this, is that as I’m starting on android, I’m not sure what can and can’t do.
– Bruno Romualdo
See help: http://stackoverflow.com/questions/21545728/dialog-fragment-with-wrap-content-coming-as-a-full-screen-how-to-make-it-as-a-h
– Geferson
And I thought that with Dialogfragment there would be no way to define a direct height in the layout because I had read something similar in a forum
– Bruno Romualdo
Great link, I’ll take a closer look at it, obg.
– Bruno Romualdo
To do yes, this link I think is clearer for you to implement: http://stackoverflow.com/questions/12478520/how-to-dialogset-dialogfragments-width-and-height. anything post there.
– Geferson