如何设置安卓设备显示为竖屏方向?

8
从以下的.xml文件中,我设置了xml以显示TabHost,但在模拟器上运行后,它同时显示了两个方向。我想设置它只显示一个方向。我该怎么做?谢谢。
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <RelativeLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:orientation="vertical">

        <FrameLayout android:id="@android:id/tabcontent"
             android:layout_width="fill_parent" 
             android:layout_height="fill_parent"
             android:layout_alignParentTop="true" 
             android:layout_above="@android:id/tabs" />
    <TabWidget android:id="@android:id/tabs"
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content"
             android:layout_alignParentBottom="true" />
    </RelativeLayout>
</TabHost>
3个回答

24

在你的manifest.xml文件中添加这行代码。

<activity android:name=".activity"
  android:screenOrientation="portrait">
</activity>
如果你只想要横向方向,那么请将 portrait 改为 landscape

8
在清单文件中的活动中设置android:screenOrientation="portrait"

0
在AndroidMainfeast.xml文件中,你会看到


<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
</activity>

在 MainActivity 之后添加 Add。

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

android:configChanges="" 可以帮助我们在旋转屏幕时防止调用onPause()和onResume()方法。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接