How to set android show vertical orientation?

2019-01-15 08:39发布

From following .xml file I set xml to show TabHost but after i run it on emulator it show both both orientation. i want to set it to show only one orientation. How do i do? THanks you.

<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条回答
萌系小妹纸
2楼-- · 2019-01-15 09:03

Set in this android:screenOrientation="portrait" in your activity in manifest .

查看更多
趁早两清
3楼-- · 2019-01-15 09:06

add this line in your manifest.xml file.

<activity android:name=".activity"
  android:screenOrientation="portrait">
</activity>

if you want only landscape orientation then change to landscape instead of portrait

查看更多
戒情不戒烟
4楼-- · 2019-01-15 09:07

In the AndroidMainfeast.xml file you will see

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

so Add after .MainActivity

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

android:configChanges="" help us to prevent onpause() and OnResume() method when we made rotation.

查看更多
登录 后发表回答