在Android开发中我们会碰到开发屏幕扭转的情况,如何固定住屏幕ScreenOrientation 呢?
在学习jetboy代码时,发现屏幕被旋转了,代查代码没有找到相关设置,在manifest.xml中找到了相关的代码:
Java代码 :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.jetboy" android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<activity android:name=".JetBoy"
android:label="@string/app_name"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4"></uses-sdk>
<!--
<uses-library android:name="android.test.runner" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.android.jetboy"
android:functionalTest="true" android:label="Jetboy Test All Runner"/>
<uses-permission android:name="android.permission.RUN_INSTRUMENTATION"/>
-->
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.jetboy" android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<activity android:name=".JetBoy"
android:label="@string/app_name"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4"></uses-sdk>
<!--
<uses-library android:name="android.test.runner" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.android.jetboy"
android:functionalTest="true" android:label="Jetboy Test All Runner"/>
<uses-permission android:name="android.permission.RUN_INSTRUMENTATION"/>
-->
</manifest>
找到这名代码:android:screenOrientation="portrait"
portrait表示横向,landscape表示纵向
如果要使Activity的View界面全屏,只需要将最上面的信号栏和Activity的Title栏隐藏掉即可,隐藏Title栏的代码:
requestWindowFeature(Window.FEATURE_NO_TITLE);
配置文件里代码:
android:theme="@android:style/Theme.NoTitleBar"
隐藏信号栏的代码:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
其它使用:
getWindow().setFlags(WindowManager.LayoutParams.TYPE_STATUS_BAR, WindowManager.LayoutParams.TYPE_STATUS_BAR);
至此Android开发中的屏幕固定问题就解决了!