Layout for unusual screens - android

Some of users downloading my apps complain that they were unable to install the app as it exited with MainActivity.class layout not being found. After investigating, I realized that those mobile phones have unusual screens.
For example, one of those phones is HTC ChaCha which screen is 480 x 320 pixels, 2.6 inches (~222 ppi pixel density). According to these specifications, it is a Normal screen, MDPI.
However, as its screen is set in the landscape mode (wide mobile screen), Android does not recognize it as Normal MDPI, but as something else and then it tries to pull XML layout from /layout dir. The Main.xml layout in this directory does not envisage such unusual screens and the layout gets broken (layout icons too big and probably pulled from HDPI drawable directory).
How to make the XML layout for such unusual phones?
PS. One more Question. When I create an emulator for this phone via Android SDK Manager, should I set "Abstracted LCD density" to 222 or keep it to 160???

The problem of the HTC Chacha is in fact it's screen aspect.
It's a "notlong" screen (like the HTC Wildfire if I'm correct).
To make a specific layout for this phone (and all screens with a 4/3 ratio), just make a layout in layout-notlong directory.
res
|---layout-notlong
|----mylayout.xml

Are you sure that the error is that the activity's class can't be found?
Several device vendors will incorrectly describe the density of their screens. The density is not derived from the physical size and pixel count. Some have done this for compatibility reasons; for instance, the original Samsung Galaxy Tab (released before Honeycomb, therefore not technically "tablet ready") reports itself as HDPI so that graphics and layouts are selected to make it use the screen more like a phone.
In regards to your layouts, if you have a decent default (in res/layout/) this will be chosen if no more specific layouts are available (e.g. res/layout-land/ or res/layout-large/). Keep in mind that each of the view ids that you reference in code must be available in all layouts. Keep them all up to date with each other or you will end up with inconsistent behaviour.
If you're diligent about making graphics for at least the main three densities (ldpi, mdpi, and hdpi) then you should not see over-large icons except where the screen is physically smaller than your layout expects it. Also, use dp in your layouts instead of px.

Perhaps the good start to identify the problem is to check the Application Error Reports
in your android market publisher account.
Click on Erros(2) just next your app in the apps listing.

Related

Android - layout-large not being selected for Samsung Galaxy S8+

In my app, I support multiple screens to a reasonable extent as per the guidelines here and here. However, the S8+ seems to be taking the layout-normal layout instead of layout-large. I remember reading that it could be due to its odd aspect ratio (18.5:9) when its setting for "use fullscreen" or something is enabled. It seems with or without this setting the result is the same (uses normal layout). I suspect there are other phones that will have this issue.
Also, interestingly, I made a generic device definition in Android Studio of that phone, with it's 2960x1440, 6.2" screen to preview the screen and Android automatically reclassified it as a tablet (and forces it to use the large layout in the preview). This leads me to believe that it would do the same at runtime on a device, but it would appear it doesn't.
How can I set my app to have these phones (perhaps those with these...problematic...aspect ratios) use the large layout it was supposed to?
As mentioned in the comment by #CommonsWare, it would be better to use dp size qualifiers, however to shed a little light on why your problem happens:
The old size qualifiers are size "buckets", they represent a range of sizes and aren't very precise. So the S8+ falls into the normal size bucket on the device (probably due to the size the device is reporting), but large on the emulator (which seems suspect to me).
If you look closely at the resource qualifier definitions listed here Providing Resources you will notice the definitions for screen size are a bit vague.. taking a unit dp to be 1/160 inch.. the screen sizes they describe are "approximately":
small: 2" x 2.6"
medium: 2" x 2.9"
large: 3" x 4"
xlarge: 4.5" x 6"
Note that all of these sizes are surprisingly small. In reality the device manufacturer decides the bucket it falls into, which is very likely why your S8+ reports "normal" and the emulator is a tablet.. by the table above, it would be.
Essentially I recommend you use the "smallest width" qualifier. You can find some hints around the values you might want on the same page linked above.

Android Virtual Device detects wrong screen size

I have been working with programmatic layout in Android Studio and i have a problem:
AVD always uses normal layout even if i use Nexus 7 which has "large" screen as its property
it is not code problem, since when i plug in my tablet it uses large layout and works fine
Any ideas where the problem might come from?
Well you are right in some sense android should take layout dependent on different densities but some mobile do not fall under specific density. Therefore android will pick up default layout from layout directory.
to support multiple screen resolution provide different layout for different screen sizes, you can make following directories in res directory like this
layout-hdpi
layout-mdpi
layout-xhdpi
layout-xxhdpi
layout-w320dp-h408dp
layout-w480dp-h800dp
layout-w480dp-h854dp
layout-w720dp-h1280dp
layout-w1080dp-h1920dp
layout-w1440dp-h2560dp
when you provide layout in all this directories you will give multiple screen support for different sizes as well

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.

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