问题
I am developing an android application that supports multi-windows feature on Android 7.0. I followed this guide on https://developer.android.com. , imported sample project https://github.com/googlesamples/android-MultiWindowPlayground I create a new resource named layout-land and did some testing. I recognized that landscape layout is inflated even though the device is in portrait mode. Check out attached images. How can I set portrait layout when device is in portrait mode.
回答1:
Assume you have two screens. One is in landscape and one in portrait. How can you say which one is in landscape and which one in portrait?
In portrait width of the screen is less than height. And for landscape width of the screen is greater than height.
Agree?
So, here, when you enter multiwindow mode your app's window no longer fits screen - width is greater than height and it is considered as landscape. That is why landscape layout resource is used.
There is no separate modifier for layout resource to be used in split-screen mode.
The only thing you can do to achieve portrait in your case is to remove layout-land.
Or you can create two separate layouts (without any modifiers such as -land
) and in activity call activity.isInMultiWindowMode();
to choose corresponding layout you want to use.
来源:https://stackoverflow.com/questions/42527558/multi-windows-in-android-7-0-always-get-landscape-layout-even-though-device-in