力"人像"方向模式 [英] Force "portrait" orientation mode

查看:208
本文介绍了力"人像"方向模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图迫使肖像模式,为我的应用程序,因为我的应用程序是绝对不适合的风景模式。

I'm trying to force the "portrait" mode for my application because my application is absolutely not designed for the "landscape" mode.

阅读一些论坛上后,我在清单文件中添加如下几行:

After reading some forums, I added these lines in my manifest file:

<application 
  android:debuggable="true"
  android:icon="@drawable/icon" 
  android:label="@string/app_name"
  android:screenOrientation="portrait">

不过,我的设备(HTC Desire的)上不起作用。它从切换肖像LO风景,而忽略从清单文件中的行。

But it doesn't work on my device (HTC Desire). It switches from "portrait" lo "landscape", ignoring the lines from the manifest file.

在多个论坛上看书,我尝试添加这在我的清单文件:

After more forums reading, I tried to add this in my manifest file:

<application 
  android:debuggable="true"
  android:icon="@drawable/icon" 
  android:label="@string/app_name"
  android:configChanges="orientation"       
  android:screenOrientation="portrait">

和我在活动课这样的功能:

and this function in my activity class:

public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

但同样,没有运气。因此,任何人有一个想法?

But again, no luck. So, anybody has an idea?

在此先感谢!

推荐答案

请勿定向到应用程序元素,相反,你应该将属性应用到活动元素,还必须设置 configChanges 如下所述。

Don't apply the orientation to the application element, instead you should apply the attribute to the activity element, and you must also set configChanges as noted below.

例如:

<activity
   android:screenOrientation="portrait"
   android:configChanges="orientation|keyboardHidden">
</activity>

这是在清单文件应用,例如, /platforms/android/AndroidManifest.xml

This is applied in the manifest file at, for example, /platforms/android/AndroidManifest.xml.

这篇关于力&QUOT;人像&QUOT;方向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆