简体   繁体   English

Android:如何为不同的屏幕尺寸强制设置屏幕方向?

[英]Android: How to force screen orientation for different screen sizes?

I use two different layout folders: 我使用两个不同的布局文件夹:

layout
layout-large

Now I want to ensure that the screen orientation is portrait if the layout folder is used, and landscape if the layout-large folder is used. 现在我想,以确保屏幕方向是,如果纵向layout时使用的文件夹,景观,如果layout-large被使用的文件夹。 How can I force this? 我该如何强制呢?

The correct directory-name for the landscape layouts is 'layout-land', see here . 风景布局的正确目录名称是“ layout-land”,请参见此处

If you do this, you don't need to do other things, Android will do the rest for you. 如果执行此操作,则无需执行其他操作,其余的将由Android完成。


If you want to change to landscape based on the size of the Screen, you can check for the screen-resolution and then set the Orientation using the 'setRequestedOrientation()'-method from the Activity class. 如果要根据屏幕的大小更改为横向,可以检查屏幕分辨率 ,然后使用Activity类中的“ setRequestedOrientation()”方法设置“方向

Maybe its too late.. But for what it's worth, you can define orientation in value for small screen and in value-large for large screen and then use it in AndroidManifest.xml . 也许为时已晚。但是,对于它的价值,您可以为小屏幕定义方向,为大屏幕定义值大,然后在AndroidManifest.xml使用它。

Have a look at my blog post . 看看我的博客文章

Please have a look at this 请看看这个

supports-screens 
android:resizeable=["true"| "false"] 
android:smallScreens=["true" | "false"] 
android:normalScreens=["true" | "false"] 
android:largeScreens=["true" | "false"] 
android:xlargeScreens=["true" | "false"] 
android:anyDensity=["true" | "false"] 
android:requiresSmallestWidthDp="integer" 
android:compatibleWidthLimitDp="integer" 
android:largestWidthLimitDp="integer

It will handle your screen. 它将处理您的屏幕。

Place to allactivities android:screenOrientation="portrait" in manifest like: 放置到清单清单中的所有活动android:screenOrientation="portrait"中,如下所示:

 <activity android:name=".View" android:screenOrientation="portrait"
            android:label="Home">
        </activity>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM