java Android的屏幕设置翻转方向

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Android的屏幕设置翻转方向相关的知识,希望对你有一定的参考价值。

  如何让Android屏幕只能上下翻转
分类: android2014-02-10 18:08  2792人阅读  评论(0)  收藏  举报
android
通常我们的应用只会设计成横屏或者竖屏,锁定横屏或竖屏的方法是在manifest.xml文件中设定属性android:screenOrientation为"landscape"或"portrait":

        <activity
            android:name="com.example.kata1.MainActivity"
            android:label="@string/app_name" 
             android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

其实screenOrientation还可以设置成很多值:
android:screenOrientation   =         ["unspecified" | "behind" |
                                     "landscape" | "portrait" |
                                     "reverseLandscape" | "reversePortrait" |
                                     "sensorLandscape" | "sensorPortrait" |
                                     "userLandscape" | "userPortrait" |
                                     "sensor" | "fullSensor" | "nosensor" |
                                     "user" | "fullUser" | "locked"]

其中 sensorLandscape就是 横屏 根据重力上下翻转, sensorPortrait竖屏 根据重力 上下翻转。
如果有兴趣,你也可以试试其他的值哦...

以上是关于java Android的屏幕设置翻转方向的主要内容,如果未能解决你的问题,请参考以下文章

屏幕翻转的解决方法

cocos2d-x 2.x 支持多个方向屏幕翻转

android 遥控器方向,Android设置屏幕方向

切换屏幕方向时保存和恢复 ButtonText

一般检查任何移动设备屏幕方向更改?

如何framework层任意设置Android屏幕的旋转方向