How to develop Android application for tablet in landscape mode and for phone in portrait mode

1k views Asked by At

How to develop Android application for tablet in landscape mode and in portrait mode for Phones?

4

There are 4 answers

0
Aniket Thakur On

You can provide alternate layouts. Create folder /res/layout-land and put your layout xml file in it.

0
Dev On

Disable the device's orientation sensor by setting the attribute in the activity tag in the manifest file like this:

android:screenOrientation="nosensor"

When you run your app, by default portrait orientation is set for phones and landscape for tablets(and hence it'll select the xml file from layout-xlarge-land). And since you've set an orientation lock, it remains in this orientation.

0
vinay Maneti On

Now to make your App screen to work in both orientations as expected, please follow the below steps:

  1. As shown in the below screenshot, under “res” folder, create a new folder with the name “layout-land”, -land appended for landscape orientation.
  2. For landscape orientation, create layout xml under “layout-land” folder with the same name as of the layout xml under “layout” folder. Note that name of the xml file in layout and layout-land folder should be same.

Screen orientation–Portrait / Landscape

and even try to mention this

<supports-screens android:resizeable=["true"| "false"]
                  android:smallScreens=["true" | "false"]
                  android:normalScreens=["true" | "false"]
                  android:largeScreens=["true" | "false"]
                  android:xlargeScreens=["true" | "false"]
                  android:anyDensity=["true" | "false"]
                  android:requiresSmallestWidthDp="integer"
                  android:compatibleWidthLimitDp="integer"
                  android:largestWidthLimitDp="integer"/&rt;

In this manner image provider

0
Roshni On

You should have to check device type programmatically (link). If the device is mobile then lock app orientation to portrait otherwise lock orientation to landscape mode.(link) And you need two layout folders - layout and layout-land.