Resource qualifier for landscape orientation only in phones - android

Is there a way to create a resource qualifier for landscape mode, but only for sphones? For large screens I'm using Fragments, so the layout in portrait mode really looks better for them. Currently my resources look like this:
resources/layout
resources/layout-w600dp
resources/layout-w1200dp
In layout, I have the layouts for the activities on phones and for the fragments in default (portrait) mode. The other two folders are for the activities in "medium" and "big" tablet screens. If I create a
resources/layout-land
To better support landscape on phones, It will be used for tablets on landscape. Duplicating the file from layout in layout-w600dp-land makes me itch... is there a way to do what I want without duplicating files?

I'm not exactly sure you're trying to accomplish but I would read through this article to see if it helps answer your question: http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html

Related

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

How does Android determine which layout to use

So, I am aware that you can define different layouts for different screens and orientations. The problem I have is in grasping which will be used when.
I am considering three devices (as an example):
Google Nexus 7
Samsung Galaxy S3
Some really small phone.
At the start, there is a main.xml in res/layout which is the default layout to be used in portrait mode. Then, you can define main.xml in res/layout-land which is the default layout to be used when the phone is held in landscape mode.
These are the two layouts which will be used for Samsung Galaxy S3 and Nexus 7 and small phones because I have not defined anything specific.
Now, I want to define a layout, specifically for the small phone and portrait mode, in addition to the ones mentioned above. It will go under res\layout-small\main.xml
My question is: How will the layout for the small screen be chosen when it is held in landscape mode?
Links by #Simon are very useful. In addition to that the sample application NewsReader.zip on android's Supporting Different Screen Sizes page will help. If you read Use Orientation Qualifiers section it tell you what you want to do.
You can define all the layouts in an XML file in the res/layout/ directory. To then assign each layout to the various screen configurations, the app uses layout aliases to match them to each configuration. Eg. for small screen portrait a file:
res/values-sw600dp-port/layouts.xml:
Its contents can be like:
<resources>
<item name="main_layout" type="layout">#layout/small_screen_portrait</item>
<bool name="has_two_panes">false</bool>
</resources>
You can see the sample app for more. Hope this helps.

Android - common techniques for scaling screen layouts

I realise this topic has been covered to death, and I have read the official and unofficial developer guides on it so know the theory. But I'm still unsure which path to take to ensure my app looks good on multiple screen sizes. My app is a simple navigation style app which is designed to be portrait only. At this stage I'm not interested in making different designs for landscape or multi-pane screens for tablets etc. I just want each screen to be scaled up/down so it looks in proportion with the screen size it is being displayed on - i.e. text and images are sized up/down as appropriate. I designed the app for a classic 480x800 hdpi device which it looks great on, I just want to make it look in proportion for the Galaxy S3/Nexus 7 etc. I'm already following these guidelines :
Using RelativeLayouts
Using DP units for padding/margins
Using SP units for fonts
Using 9-patch images for buttons
However I'm finding it still looks small and a bit lost in the middle of the screen on the larger devices. In particular, my main menu screen is a grid of 6 image buttons which I can't get to scale well. I don't want to have multiple copies to maintain of the same screen (normal/large/xlarge), just want one layout. I was considering the following :
Using value-normal/value-large etc. folders to store XML files with DP/SP values for sizes of images/text
Changing RelativeLayouts to LinearLayouts with weights (although I initially struggled with LinearLayouts and changed to RelativeLayouts
Are either of these valid approaches, or is there a better approach?
Personally, I would go with the first option. While this will work well for phones, it will make the layout seem somewhat bloated on tablets. Hence, another approach would be to create separate layouts for tablets and place them in the layout-large and layout-xlarge folders for 7" and 10" tablets respectively.

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

Portrait, Landscape in Android app

I am designing with LinearLayout which is working for portrait but landscape it does arranged properly. I do not use x,y positions. If I change anything in xml it affects the design -- how do I design both portrait and landscape?
You can specify a layout-land folder, to put all your landscape layouts (duplicate them, but with little differences in order to they show properly in corresponding orientation). In order to avoid this, you should work with RelativeLayouts. But if it's too late and you don't want to change everything, you can create the mentioned folder and make the proper layout changes.
So you will have a
layout/activity.xml
and a
layout-land/activity.xml
If your app is big, it might become a pain to make every change two times, but it's not so bad.
Not recommended, but you can also avoid changing orientation by supporting only portrait orientation in your app: you would have to put "android:screenOrientation="portrait"" in your app's Manifest then.
You can define a second xml file that is the layout for the landscape version. That file must be named the same and placed in a layout-land folder:
i.e.
Portrait:
layout/main.xml
Landscape:
layout-land/main.xml

Categories

Resources