sw320dp layout blocks xlarge layout - android

I made an extra layout for the S3 (rebel of all layouts) and people said, using a layout-sw320dp is good for the s3. Everything worked, the s3 chose this folder and the layout looks great on the s3.
But when I try to run my app on a 10" tablet, the tablet uses the same folder like the s3 which is totally wrong.
How can I make the sw320dp layout visible only to the s3 or at least how can I make 10" tablets use the xhdpi folders? I already read, that the android system thinks, because sw360 is a "new" type, it's the best. But I don't know how I can avoid that..
Thanks

This is because of higher order of precedence of sw<???>dp qualifier in Android. res-sw<???>dp has got the 2nd highest precedence in the order of qualifiers.
See Configuration qualifier Table. This is the default order in which Android takes the directories in resource folders. So basically whatever folder you provide which have lower precedence, Android wolud not take that. See How Android Finds the Best-matching Resource.
Here sw320dp means devices with at least 320dp of shortest width. Both S3 and 10" tablets come under that. So Android always take that folder for devices which have shortest width of 320dp.
These are some alternatives you can do:
Make layouts like drawable-720dp(10") and drawable-600dp(7") for
tablets. The problem with giving sw<???>dp is that it's been introduced only in API 13 only. So tablets with API < 13. can't use that.
Change the layout for high density phones to layouts with lower
precedence values.
I basically support this method. This way you can give more support
to lower API devices.

Related

Android Galaxy S4 uses values-large?

Problem:
I am testing my app using the Eclipse/ADT bundle. On an AVD created to emulate the Galaxy S4 (a device defined as being "normal" in size) the OS is selecting the XML files from the values-large folder.
The Android operating system is ignoring all other values folders I have defined in an attempt to differentiate the S4 from tablets.
Given the following folders, it selects the values-large folder for the S4:
values-large
values-sw720dp
values
values-normal-hdpi
values-normal-mdpi
values-normal-xhdpi
values-normal-xxhdpi
values-normal
The problem is that I have Master/Detail (ListFragment/Detail-Fragment) two-fragment display that only displays correctly on large screens (tablets). It does not display correctly on the S4, because of the device's size. On a device smaller than 6" wide, the icons end up getting displayed on top of the text, instead of to the right of the text. The only difference is with the S4 in landscape orientation.
The S4 is the ONLY normal sized device that can show the two-pane layout in landscape orientation. The Nexus 4 and others cannot. In landscape the extra density of the S4 is what makes it work.
I also don't want the S4 to use the dimens.xml file that is in the values-large directory.
Questions:
Is this normal/expected behavior? Does the OS classify the S4 as a "large" device? The OS has ignored every other folder name I have tried to use to target the S4. So, it prefers the pre 3.2 names over the newer ones.
In other words, when I attempt to use the newer folder names, like values-sw720dp, the OS still chooses the large folder.
I have two AVDs. One I created to match the specs of the S4. The other is the Sony Xperia Z1, that has the same specs and is available when you install the Sony SDK. Both AVDs are setup with size=normal. I have checked each to makes certain there is no mistake in their setup.
Thanks.
EDIT
I have a new LG G2, which is similar to the S4 in size and density. It does NOT use the values-large directory. I think it is using values-normal-xxhdpi, but need to run more tests (changing dimension values in the dimens.xml) to see what directory it is choosing.
values-large etc are deprecated with android 3.2 (?). It was replaced with things like values-sw720dp and there is basically not a single device out there running android 3.0 or 3.1. Any device running android 2.x is most likely a medium sized phone.
This means, there is no need of using this old qualifiers.
values-sw720dp means, smallest width = 720dp I doubt, your S4 is that wide.
You should use a qualifier like values-w720dp, which means width = 720dp where width depends on your current orientation.
It's way better than relaying on port or land combination because it shows the two pane layout for large displays having 720dp width in portrait orientation too.
Master/Detail two-pane layout for large screens (any orientation)
That seems fine. The implication is that you will use this for -xlarge as well as -large.
and medium screens with high dpi in landscape orientation
First, I do not know what "medium screens" are, as that term is not used in Android development.
Second, I have no idea why you think this would be appropriate. Screen density should not impact the decision of whether to show one or two panes. I would be interested to know applications, written by experts, you see taking this approach.
At first I thought it was the second folder (sw720dp) causing the problem
Note that you have not stated what the problem is.
The Sony Xperia Z1 AVD
I am not aware that SONY distributes emulator images for their devices.
does the same thing as the S4 AVD
I am not aware that Samsung distributes emulator images for their devices.
Is there a values folder I can use to make the Galaxy S4 not choose Master/Detail at all, but still allow tablets to use it?
Ignoring your "medium screens with high dpi in landscape orientation", use -large or -xlarge for tablets. The Samsung Galaxy S4 will not use -large or -xlarge resources, as it is a -normal device. This was confirmed using both the GT-I9500 and the SGH-I337 versions of this particular model.
Is there a way I can make it use Master/Detail for the S4 only when in landscape?
You can use -normal-land to identify -normal devices in the -land orientation. Note that screen size (-normal) is a bit of a fuzzy match, in that Android considers that valid for devices in that size class or larger. Hence, -normal-land would be used by -large-land and -xlarge-land devices as well, in the absence of better matches.
(Note that density qualifiers are even fuzzier -- -mdpi will be used for any device density, in the absence of a better match, as density qualifiers are designed to be used only on drawable directories, where Android can apply resampling algorithms. Using density qualifiers on anything other than drawables and maybe dimension resources is a code smell.)
Personally, I would not use a dual-pane strategy for -normal-land devices, as -normal goes all the way down to 3" diagonal.
This is all in the Eclipse/ADT bundle using the emulator.
My guess is that this is where your problems are coming in.
Unless you downloaded something from a device manufacturer (e.g., Amazon with their emulator images for the Kindle Fire series), NEVER say that you have a "Sony Xperia Z1 AVD" or a "S4 AVD". You are lying to us and, worse, you are lying to yourself. At best, you have an emulator image that you think that you have configured to match the specifications of those devices. However:
That assumes you got the configuration correct
That assumes that the device manufacturer has not changed the behavior of their device at the firmware level
That assumes there are no emulator bugs
You are certainly welcome to say that you are testing things on -normal -hdpi emulators, or the like, as those are things that you directly control via the Device Definitions tab of the AVD Manager.
After reading your comments, I noticed you said you said the Galaxy S4 screen size you defined was 4.9"? All the specs I've seen say it's 5" which will actually change the size in Device definitions from "normal" to "large" once you correctly set the S4 and Nexus 5 to 5".
Edit the Galaxy S4 emulator's definitions to 5" so you have the right screen size, it will auto-change the size to large, so you will need to decide if you need to switch it to normal then go from there. Also, for those wondering, once that avd starts, it does say that it's pulling from the sw480dp folder, so in your case, you would need a new folder:
values-sw480dp or to eliminate large devices in this bucket, values-normal-sw480dp

Android Phone and Tablet UI

I have made one app which is working fine for both Tablets and Phones. But as we know we should have a different layout for tablets( such as bigger font and images etc).
My question is how to provide the layouts such that they are only picked by tablets and not phones.
Example: If i provide xhdpi or hdpi layout thinking of these as tablet then it may be picked by some device also which is using this same configuration.
So how to be sure that a current device is tablet or phone and provide a specific layout for it?
My question is how to provide the layouts such that they are only picked by tablets and not phones.
Either use the classic screen size buckets (e.g., res/layout-large/) or come up with your own buckets using -swNNNdp (e.g., res/layout-sw600dp/ for resources to be used on devices whose shortest width is 600dp or higher).
This is explained in the documentation here, here, here, and perhaps a few other spots as well.
Example: If i provide xhdpi or hdpi layout thinking of these as tablet then it may be picked by some device also which is using this same configuration.
-xhdpi and -hdpi are screen densities and have nothing directly to do with screen size.

Designing layouts for phones and tablets

Okay i am familiar with this site and what it says
http://developer.android.com/guide/practices/screens_support.html
But im still having a problem.
I am designing layouts for phones and tablets from gingerbread to jelly bean.
I had started with a basic layout folder and designed everything for a galaxy nexus phone. now im going back and adding tablets. one question here is should i use layout-xlarge/layout-large or layout-sw600dp/layout-sw720dp? im guessing the smallest width is what i should be using.
But thats not the issue.
This issue is im trying to do that layous for Galaxy Nexus (720x1280) and Nexus S (480x800) These are much different yet eclipse doesn't seem to let me differentiate.
So i just want to be clear on what i should be doing to do this right. is this what i should have to cover the devices i want to?
layout-hdpi
layout-xhdpi
layout-sw600dp (instead of layout-large)
layout-sw720dp (instead of layout-xlarge)
will doing those layout-hdpi and layout-xhdpi separate the layouts for a Nexus S and Galaxy Nexus?
First, the layout-sw are based on dp, Density-independent pixels, rather than pixels. You can think of dp as 'actual size' pixels i.e., 1dp is the same physical size no matter what device is being used.
Therefore the Galaxy Nexus, which has a 720x1280 pixel screen is only 360x640 dp resolution and there is no overlap between a phone and the higher sw600+ folders.
The large/xlarge buckets will continue to work on all tablets, but if you need finer grained support or alright only using tablet layouts on Android 3.2+ devices, then you only need the sw--dp folders. You can also use both without copy/pasting your XML by using a reference file, as detailed in the below blog post.
More details on how to support multiple screens can be found in Supporting Multiple Screens guide and some of the reasoning behind why you'd want to use the new sw---dp buckets can be found on the Android Developers blog post announcing the feature.
Just use layout-large and layout-xlarge. When you're developing the layouts and want to know what it looks like on a certain device, just change the view and it will pull the appropriate XML from the correct folder.

Android layouts tree, human readable explanation?

If I write a message today is for getting details about the folder tree layouts in android.
I want to warn you now, I have read all the pages of the official documentation regarding support for different screen sizes, it is very complete, but in my opinion not really human-readable. So please, don't just copy a link to the documentation.
My question is simple:
What is the best combination of layouts folders to ensure maximum support for different screen sizes ?
Before Honeycomb, we had layout, layout-large, layout-xlarge, etc ... That's OK, but now we have sw600dp, sw360dp, sw ... Arggh stooop !
In my case, I have to make an application for android and I need to ensure maximum support.
I have some devices on hand:
Galaxy Note 10.1
Galaxy Nexus
Nexus S
Nexus 7
And ... Samsung Galaxy Spica (GT-5700)
And here are my layouts folder now:
layout
layout-sw360dp (for Galaxy Nexus)
layout-sw600dp (for Nexus 7)
layout-sw720dp (for Galaxy Note 10.1)
layout-480x320 (for GT-5700)
(and layout-*-lands)
I'm really not sure of doing things right, I thought the Nexus S would pick the layout folder, but it takes the layout-480x320, why?
So I have some questions:
1. Am I in the right direction?
2. Is it always necessary to create folders layout-large, layout-xlarge ... ? If so what should I put inside?
3. I do think the folder layout-480x320 is not a good solution, but I try to do things well and not make this folder is not enough.
Could someone tell me clearly how to do things right?
Thank you!
What is the best combination of layouts folders to ensure maximum support for different screen sizes ?
That is impossible to answer in the abstract.
Am I in the right direction?
-layout-WxH has been deprecated for a couple of years.
Is it always necessary to create folders layout-large, layout-xlarge ... ?
No. If you are not concerned about Android 2.x -large or -xlarge devices (e.g., Kindle Fire, NOOK) or Android 3.1 devices (0.4% of the market as of November 2012), then skipping -large and -xlarge is perfectly fine.
However, -small may still be relevant for you, for devices with very small screen sizes (under 3" diagonal), if you are supporting such devices.
I do think the folder layout-480x320 is not a good solution
Correct.
I try to do things well and not make this folder is not enough.
Then design a more flexible UI for -layout.

layouts for different screen sizes, why is default being picked?

I have created layout files for small, large and xlarge screens sizes, but when I load my app on a Samsung S3 emulator, with the resolution of 720 x 1280 it is still the default layouts which are being used.
I do not understand why android is not using my specific layout files.
I have placed the layout files in the folders layout-large, layout-small, layout-xlarge under the folder layout.
Hope someone can point me to what I am doing wrong.
Thanks.
The screen size buckets you are referring to are deprecated since Android 3.2 (API level 13?). If you are targeting later versions of Android then you should be using the "smallest width" qualifier to enable a finer grain control.
The Samsung Note for example will leverage the old "layout-large" bucket but it doesn't respond well to mini- or normal tablet layouts. These devices are normally running Android post 3.2 (the DELL Streak and original Galaxy 10.1 tab are the exception). To differentiate in this instance supply a layout-sw520-port and layout-sw520-land resource folder and place the layouts here. Further differentiations can be made for Nexus7 type devices (sw600) and so on. Note there are reserved pixels on screen (notification/action bar etc) so the physical smallest width DPI is not precisely what your layout will respond to (albeit predictable close).
Diana Hackborn (hackbod) wrote a comprehensive blog post on the subject describing the motivation s behind the change and the sorts of problems (cf. Your issue) it solves. Google have also put together some advice on designing for multiple configurations as part of their tablet drive. Have an Android Dev Guide trawl should you hit further issues.
Samsung S3 is in the "normal" category.
What I found helped me greatly to get layouts which scales to different resolutions was layout_weight="1" and layout_width="0dp", just in case someone drops by this question wondering why there layouts do not scale in some areas.

Categories

Resources