8

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>
Sujit
  • 10,137
  • 9
  • 38
  • 43
April Smith
  • 1,790
  • 2
  • 26
  • 52

3 Answers3

24

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

nhaarman
  • 94,943
  • 53
  • 240
  • 273
Niranj Patel
  • 36,011
  • 11
  • 98
  • 132
8

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

Sujit
  • 10,137
  • 9
  • 38
  • 43
0

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.

Hamza Rahman
  • 616
  • 7
  • 17