在android中设置应用程序的屏幕方向

时间:2013-12-20 06:13:11

标签: android

以下是我设置屏幕方向的代码

 <activity
        android:name="com.srikanth.lullaby.MainActivity"
        android:label="@string/app_name"
         android:configChanges="orientation"
         android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
    </activity>
    <activity
        android:name="com.srikanth.lullaby.SoundRecordingActivity"
         android:configChanges="orientation"
         android:screenOrientation="portrait"
         android:theme="@android:style/Theme.Black.NoTitleBar" >
    </activity>
    <activity
        android:name="com.srikanth.lullaby.RecorderActivity"
         android:configChanges="orientation"
         android:screenOrientation="portrait"
         android:theme="@android:style/Theme.Black.NoTitleBar" >
    </activity>
    <activity
         android:name="com.srikanth.lullaby.MediaplayerExample"
         android:configChanges="orientation"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
    </activity>
    <activity
        android:name="com.srikanth.lullaby.MediaPlayerActivity"
         android:configChanges="orientation"
         android:screenOrientation="portrait"
         android:theme="@android:style/Theme.Black.NoTitleBar" >
    </activity>

但它无法正常工作,当我旋转屏幕然后应用程序改变其方向 如何解决这个问题。

4 个答案:

答案 0 :(得分:1)

试试这个..

只需删除

android:configChanges="orientation"

或者在你的java中在setContentView(R.layout.yourlayout);

之后添加这一行
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

答案 1 :(得分:0)

尝试为每个活动代码添加如下内容:

<activity
        android:name="com.srikanth.lullaby.RecorderActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"/>

答案 2 :(得分:0)

试试这个

 android:configChanges="keyboardHidden|orientation"
            android:screenOrientation="portrait" 

在Application标签中使用主题

 android:theme="@android:style/Theme.Black.NoTitleBar"

答案 3 :(得分:0)

android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation|screenSize"

The android:configChanges line prevents onResume(), onPause() from being called when the screen is rotated. Without this line, the rotation will stay as you requested but the calls will still be made.

keyboardHidden and orientation are required for < Android 3.2 (API level 13), and all three options are required 3.2 or above, not just orientation.