问题
I'm getting screen size using this code:
getWindowManager().getDefaultDisplay().getRealSize(size);
sw = size.x;
sh = size.y;
I'm using it for specifying DialogFragment width and height:
@Override
public void onResume() {
super.onResume();
int sw = Util.getInstance().getScreenWidth(getActivity());
int sh = Util.getInstance().getScreenHeight(getActivity());
getDialog().getWindow().setLayout((int)(sw*0.6), (int)(sh*0.6));
}
*I need to specify the width and height of the dialog in onResume.
It's working but if I have the dialog present in screen, and I lock the device, if I unlock the device exactly when I'm rotating the device, then, the values are getting inverted, so the dialog is being displayed with inverted width and height. I can't understand why, because all the activities in my application are landscape:
<activity
android:name=".activities.GameActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="landscape" />
So, how can I avoid this problem? and why it's happening if the dialog is being displayed in a landscape activity?
来源:https://stackoverflow.com/questions/58573894/inverted-width-and-height-when-unlocking-with-device-rotated