Home » Android » layout – How to set android show vertical orientation?

layout – How to set android show vertical orientation?

Posted by: admin June 15, 2020 Leave a comment

Questions:

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>
How to&Answers:

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

Answer:

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

Answer:

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.