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.
Related
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
I will get straight to the point. I have my application finished and I am trying to get the layout to work on different screen sizes. My problem is with a small screen size, say 3.7" or 4". I have a layout-small,layout,layout-large, and layout-xlarge folders with different layouts for each. For Nexus 4,5, and 6, the small layout is associated with them, when I want "layout" as I used a bigger phone for those layouts.
I wanted to use the layout-small folder for Nexus One and Nexus S, as those are smaller phone and I used those emulators for the layout. For whatever reason, when I use a small phone like the Nexus One, the layout extends beyond the page while being associated with the layout-small folder, while when using the nexus 4 or 5 phone, the layout looks fine, while being associated with layout-small. It seems like Nexus One,S,4,5,6 are being shown as associated with layout-small, but are actually using layout. Any help would be greatly appreciated.
I should add that I tried doing layout-small,layout-normal,layout-large,and layout-xlarge, but everything that was associated with layout-small turned to layout-normal, and layout-small was completely dropped
Start with http://developer.android.com/guide/practices/screens_support.html You should also consider the orientation as a qualifier. The "small", "normal", "large", etc is not exact and you need to find out which it is for each device (emulator) you are testing with. Just as a test, create the folder structure with all qalifiers and have a single layout in each with a single text view that is hard coded with the resource path.
Example
res/layout-small-land/test.xml android:text="layout-small-land"
res/layout-small-port/test.xml android:text="layout-small-port"
res/layout-normal-land/test.xml android:text="layout-normal-land"
res/layout-normal-port/test.xml android:text="layout-normal-port"
I am developing an Android Application that supports all kind of Android devices like mobiles and tablets. But it's time consuming to create multiple folders (small, normal, large and xlarge android xml layouts) to support all the Android devices. Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc?
You only need to create unique layouts (ie. *layout_mdpi* ) if you want something unique for that particular screen size.
If you want to use the same layout on all different screen sizes, you will only need to create a single layout (in the layout folder).
Only if you want to customize a particular layout would you need a new FOLDER in layouts (named: layout_mdpi) in that folder you would have multiple copies of customized layout with same name (ex. my_layout.xml)
To clearly answer your question - you will only need the layout folder and no other ones in your casel
Ex.
res\layout\my_layout.xml // this folder is all you need if this layout will work on all screen sizes
res\layout_mdpi\my_layout.xml // you ONLY need this if you are presenting something unique on this screen size.
In Android we need to maintain different folders for the layouts with different resolution reason behind it is the use or the resolution of the Android Device on which the application gonna execute.
small Resources for small size screens.
normal Resources for normal size screens. (This is the baseline size.)
large Resources for large size screens.
xlarge Resources for extra large size screens.
Android OS select the specific layout it self by checking the compatible device and its resolution.
So, better to create folders to support in multiple screens
For More Info refer this
Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc
Consider this, you have a button (with match_parent) that stretches full width of a screen in portrait mode of a 4 inch phone, that's fine it looks alright, but then that same layout on a 10 inch tablet in portrait is now 3-4inch wide, that's not great looking.
"So what" you say, make it wrap content, okay then so the button now only fills up part of the width on phone, still looks okay but then on a tablet you have huge amount of space now either side of the button, maybe that's looks okay, maybe not.
Maybe same button on a smaller screen takes up too much space?
Now apply the above to every single layout element in your app.
Do you think it'll look good, using the same layout, do you think your users will be okay with an app that was so little care to its UI and UX?
SO, in conclusion, yeah it's possible to only use one eg normal, for all devices but it'll probably look terrible on most of them.
I have read lots of post on this forum and others about using a different layout depending on the device being used.
Below is a screenshot of my layout folder at the moment:
Now, I have tried many different variations to try and get the XML layout to change. The project is designed using a phone and I'm now testing on a 10.1 inch Samsung Galaxy tablet.
Despite all those layouts my app still uses the default .xml file.
Any ideas where I'm going wrong or other variations to try?
I should say I lock the user into portrait mode hence a few layouts with -port.
Any help would be great
thanks
You need to have your layout-large, layout-sw400dp-port,... folders at the same level as your layout folder instead of having them inside the layout folder.
Your folder structure should look like -
/res/layout/
/res/layout-large/
/res/layout-sw400dp-port/main.xml
...
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