Inverted width and height when unlocking with device rotated

允我心安 提交于 2020-01-25 09:20:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!