================================= Problem description ========================== =
Hello everyone, I wrote an application on Android and defined a myalterdialog inherited from alertdialog.
The getwindow (). setlayout method adjusts the width of the diyout according to the screen size. However, the strange thing is that once I call getwindow (). after setlayout (windowmath * ratio, wrap_content), the dialog window is no longer centered. I then tried to use getwidnow. the setgravity () method does not work either. I don't know why.
=============================== Solution 1 ========================== ===
If you only want to make the alertdialog adaptive screen width, you do not need to overwrite an alertdialog class, directly new alertdialog. builder (this ). setview (R. layout. alertdialog), dynamically set the bandwidth of the control in the alertdialog layout in the code.
A question about centering custom alterdialog