How to set orientation in two different mode , in two layout?

我只是一个虾纸丫 提交于 2019-12-03 23:05:44

问题


I have layout that is called Main.XML and I set the orientation to portrait in my AndroidManifest.xml. I designed this layout for Honeycomb too and placed it in the layout-xlarge-mdpi folder, but I want to use the Main.XML in layout-xlarge-mdpi only in landscape orientation.

Now, how can do this?

Thanks


回答1:


You can place your main.xml in layout-xlarge-land, then it will be used only in landscape orientation
Refer Supporting Multiple Screens (Using configuration qualifiers)

Android supports several configuration qualifiers that allow you to control how the system selects your alternative resources based on the characteristics of the current device screen. A configuration qualifier is a string that you can append to a resource directory in your Android project and specifies the configuration for which the resources inside are designed.

Edit: If you provide an main.xml in layout folder and another main.xml in layout-xlarge-land, then

  • for an extra large landscape orientation it will take the main.xml from layout-xlarge-land

  • for all other, that is in landscape or portrait orientation it will take the main.xml from layout

Refer Providing Alternative Resources for more details




回答2:


Create a layout-xlarge-mdpi-land folder and place your main.xml in that




回答3:


I think this could be done like this:

  1. Detect screen size programmtically in you onCreate. http://www.mail-archive.com/android-developers@googlegroups.com/msg144381.html

  2. Set orientation according to screen size, like this:

    if(screen size is large) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Not sure if it's the best way though.




回答4:


In AndroidManifest insert the following code in whichever activity you want to run in landscape mode(In this case Main Activity)

android:screenOrientation="landscape"


来源:https://stackoverflow.com/questions/6557107/how-to-set-orientation-in-two-different-mode-in-two-layout

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