Android Layout Folder for Devices/Tablets which are always in Landscape - android

I'm developing an android app for phones and tablets.
I want all of the devices to use portrait layout. I made a 'layout' folder for it. But, there are some X number of devices which are always in landscape mode. Probably, large tablets. So, I made a 'layout-land' folder too.
Which folder I need to add so that X amount devices will always display landscape layout only, while other devices will always display portrait layout?
Main requirement is to have only portrait layouts displayed. But, display Landscape layout when device itself is in landscape mode(default). I am talking about devices that display drawer in landscape mode, and the ones that open landscape layout of apps only.
Is this automatic?
I have android:screenOrientation="portrait" in manifest.
I can't test this as I don't have a tablet/large device.
I have already looked at this question and other similar questions.

Add the below line in your onCreate() method before setContentView()
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORT‌​RAIT);

Related

Android Studio: multiple layouts, specifically landscape tablet

I am creating an application for a school project within Android Studio. I am required to make the application run on both phones and tablets in both landscape and portrait modes. I have created 3 different layouts for my homepage by opening the Design View and selecting Create XXXX Variation from the Orientation For Preview Section. So now I have a variation for portrait phone, landscape phone, and tablet but I still need one for landscape tablet. I noticed there is a Create Other Variation but I am not exactly sure how I would go about setting that to landscape tablet. Any advice is appreciated
For reference, here is what my layout folder looks like with my different variations.
Click Create Other.. Select Orientation from Available Qualifiers box. Click >> button. In Screen Orientation select Landscape. In directory name paste this : layout-sw600dp-land
A new folder will be created with the same name having activity_main.xml in sw600dp(tablet 7" size) in landscape mode. Configure as per your requirement.
For a tablet you might use resource directory large, xlarge and large-land, xlarge-land.

How to use tablet-specific layout when in landscape mode?

I have defined a tablet-specific layout in the res/layout-sw600dp folder. Now. It loads correctly in tablet emulator and is checked and managed by code as expected. The problem is that I cannot access this layout variant to use in mobile emulator after I check that orientation is landscape. When I type in code R.layout., no hint is given as to the specific tablet layout, only one instance is given, activity_main. How can I use that tablet layout in the landscape orientation as well?
./app/src/main/res/layout-sw600dp/activity_filter.xml
./app/src/main/res/layout/activity_filter.xml
The "smallest width" qualifier doesn't care about device orientation. You'll have to make a copy of your layout and put it in the res/layout-land/ directory if you want that same layout on phones in landscape.
If you don't want to have two exact duplicate layouts (one in sw600dp and one in land), you can look into using a resource alias: https://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters

Multi-windows in Android 7.0 - Always get landscape layout even though device in multiwindows portrait mode

I am developing an android application that supports multi-windows feature on Android 7.0.
I followed this guide on https://developer.android.com.
, imported sample project https://github.com/googlesamples/android-MultiWindowPlayground
I create a new resource named layout-land and did some testing. I recognized that landscape layout is inflated even though the device is in portrait mode.
Check out attached images.
How can I set portrait layout when device is in portrait mode.
Assume you have two screens. One is in landscape and one in portrait.
How can you say which one is in landscape and which one in portrait?
In portrait width of the screen is less than height.
And for landscape width of the screen is greater than height.
Agree?
So, here, when you enter multiwindow mode your app's window no longer fits screen - width is greater than height and it is considered as landscape.
That is why landscape layout resource is used.
There is no separate modifier for layout resource to be used in split-screen mode.
The only thing you can do to achieve portrait in your case is to remove layout-land.
Or you can create two separate layouts (without any modifiers such as -land) and in activity call activity.isInMultiWindowMode(); to choose corresponding layout you want to use.

Seek for a better way to set different layouts for phone and tablet in landscape mode

In my android app, I want to load different layouts for phone and tablet in landscape mode, the layout in tablet landscape is the same as portrait in both.
So my layout folder in res is like layout(default), layout-land(for phone landscape), layout-sw600dp-land(for tablet landscape). But layout(default) and layout-sw600dp-land(for tablet landscape) is totally the same. I want to optimize this, any help is appreciated.
I plan to use layout alias, but I cannot understand the sample code in website, what I doubt is if I need to load the layout in the code, which xml file should I use?

How to handle size and position of controls in Android's Activity for portrait and landscape orientation?

I want to desing a GUI for android's tablet. By default i want to use landscape orientation of this application, so i placed the controls (text boxes, text views etc) accordingly, but when i change the orientation of tablet from landscape to portrait, whole GUI of activity gets distrubed. Can anybody guide/help me what is the best approach for designing of GUI in android such that controls appearance should remain correct in either orientation (portrait or landscape)? Thanks in advance.
You have to create another folder in the res directory called "layout-land". Put the layout file for landscape in this folder and the one for protrait mode in the normal "layout" folder. Both files must have the same name. Android will automatically chose the correct layout depending of the current orientation of the device.
Check the link below, it will provide all information about how to design an application to support multiple screens with different sizes and resolutions.
Supporting multiple screens

Categories

Resources