Android開發中如何固定屏幕顯示!

在Android開發中我們會碰到開發屏幕扭轉的情況,如何固定住屏幕ScreenOrientation 呢?

在學習jetboy代碼時,發現屏幕被旋轉了,代查代碼沒有找到相關設置,在manifest.xml中找到了相關的代碼:
Java代碼 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<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開發中的屏幕固定問題就解決了!

原文作者:sdhjob

原文鏈接:http://blog.csdn.net/sdhjob/archive/2009/12/22/5054166.aspx

發佈了7 篇原創文章 · 獲贊 4 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章