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

前端 未结 4 1249
猫巷女王i
猫巷女王i 2021-01-07 17:26

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

相关标签:
4条回答
  • 2021-01-07 17:41

    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.

    0 讨论(0)
  • 2021-01-07 17:47

    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

    0 讨论(0)
  • 2021-01-07 17:51

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

    0 讨论(0)
  • 2021-01-07 17:54

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

    android:screenOrientation="landscape"
    
    0 讨论(0)
提交回复
热议问题