imso 0 Junior Poster in Training

How should i reorient an android application in landscape mode once an apps is started?? I started an app but it does not automatically switch to landscape mode.. I tried writing it to "horizontal" but it does not work..

<LinearLayout xmlns:android=""
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

Dani AI

Generated

Setting a layout to arrange its children horizontally only changes view placement — it doesn't rotate the screen. 's LinearLayout orientation controls child layout, not the Activity's orientation. To make the app start and remain in landscape you need to tell the Activity (not the layout) to use landscape.

Add the attribute to the Activity entry in AndroidManifest.xml (inside the <application> block):

<activity android:name=".MainActivity"
          android:screenOrientation="landscape" />

If you want the device sensor to pick a landscape direction (left or right) use sensorLandscape instead of landscape. To lock at runtime from an Activity:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Call that in onCreate() (import android.content.pm.ActivityInfo).

Better practice: provide separate layouts for landscape rather than forcing orientation whenever possible. Put alternative layouts in res/layout-land/ so the system loads them when the device is rotated. If you prefer to handle rotation yourself and avoid the default Activity restart, add:

android:configChanges="orientation|screenSize"

to the activity and override onConfigurationChanged(Configuration newConfig) to update UI. Note: including configChanges means you must handle resource updates manually.

Troubleshooting tips: confirm the screenOrientation attribute is on the Activity entry (not the layout), check for any code that later calls setRequestedOrientation(), verify the device/emulator auto-rotate setting if you rely on sensors, and prefer res/layout-land for UI differences instead of locking orientation unless absolutely needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.