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

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.

Related

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.

Using appropriate layout markup according to screen resolution

I've got a design list for 480x800, 1024x600, 1280x800. How do I ask android to use exact markup based on user screen's resolution ?
As far as I know there're only abstract means(hdpi,xdpi) for solving resolution difference.
How do I ask android to use exact markup based on user screen's resolution ?
Talented developers don't do that. Talented developers realize that only a percentage of Android devices run at the resolutions listed above, just as desktop Web browsers do not run at only three window sizes. Talented developers work with the graphics designer to come up with fluid layouts for different screen sizes (e.g., -normal, -large, -xlarge), which may or may not run at the aforementioned resolutions. For example, there are devices with screen sizes ranging from 4" to 7" that run at 800x480, and there are devices with screen sizes from 4.5" to 10.1" running at 1280x800 (or thereabouts).
As far as I know there're only abstract means(hdpi,xdpi) for solving resolution difference.
-hdpi and -xhdpi have nothing to do with screen resolution. They are for screen density. Density is independent of resolution, and density is largely independent of size.
Create folder based screen width or height. For example
res/layout-w480dp, res/layout-w1024dp, res/layout-w1280dp
Or
res/layout-h800dp, res/layout-h600dp
Read more here, Table 2. Configuration qualifier names.
Afaik, you can markup the layout folder by that is the minimum required screen resolution for the layout you can set one to min600 and one to min 800.
I think this markup scheme is supported in honeycomb and above and since these are tablets resolutions, they will have either anyway.
see this and this

Large screens layout not as expected

I developed and application and uploaded all the images in the respective drawable folders (different pixels for different desnities).
Now I am confused when it comes to layout. If I used the layout editor with 4.1 inc (thats considered Med screen I guess?) everything looks great.
Now when I use the editor with 10.1 inch which is the tablet, then I see icons very small and the text is small. I have not run the emulator yet.
So I am wondering:
1- why would the text be small although I didn't specify text size? Shouldnt scalle appropriately? or should I give it a specific size for bigger layouts?
2- Why the icons are small given that I provided the different drawables? I thought it would scale up accordingly.
Please don't give me the supporting multiple screens link in android as an answer, as I already went through it and still no luck with above. I need your personal advice as I think I am missing something here
Thank you so much in advance
Android support for different screens is a little tricky. That's because you can have large, small, medium and xlarge screens, plus high, medium and low density ones. There are a dozen possibilities (xlarge low density, small high density) and not a single resolution is defined. So you must know the principles which the API is designed upon and must define your layout thinking about the role the widget has inside your UI. You also must bear in mind that your layout won't be pixel perfect on 100% of devices, so your aim should be being usable on all possible devices.
In your specific case it seems that either you don't manage to specify the correct resources, or the system doesn't pick up the right ones for you, but I must remark that it doesn't make sense on Android to talk about big, small and scale: you should design your layout with a (good) webdeveloper mindset, who daily deals with tons of different displays, resolutions, physical sizes and even devices.
I also suggest not using the graphical builder if you are new to Android, because you really need to know how Android lays out components, otherwise you will come back to SO very often :)
If you do not specify the text size in your layout file Android will take the default value, which is most likely in DIP (density independent pixel) therefore it will be the same physical size on any devices. That should explain why the text looks so small on your 10 inch tablet.
What I would do in this case is have 3 layouts for each activities and specify the text size for larger devices (given you already like the look on phones) and put them in this folder scheme :
res/layout/layout.xml // phones
res/layout-sw600dp/layout.xml // 7” tablets
res/layout-sw720dp/layout.xml // 10” tablets
Information above was taken in this article. I have this applied in my current personal project and so far it works like a charm.
Secondly, as far as icons go, I'm no drawable expert but if you provided the same file in each folder (like I think you did from what I understand in your question), it will not make it scale. You'll have to create 4 difference icons, one for each possible pixel density.
Information about icon sizes can be found on this page.
Hope this is of some help to you.
My experience with the Android device zoo drew me to the sad conclusion that the built-in screen size/layout facility is useless. Cases in point, straight from support:
a 10 inch tablet with Android 2.2. Screen size xlarge is not supported by Android 2.2
Kindle Fire, which is 7 inch and claims it's xlarge.
I ended up putting all three layouts (med/large/xlarge) into layout, loading one based on run-time density and resolution, and providing an option for user to force a specific layout.
Just sayin'.

Layout for unusual screens

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.

What is the best screen resolution for an Android AVD?

This is might seem to be a sort of silly question to ask but I would like to know while testing our apps what is the best resolution to be used (HVGA/WVGA/QVGA?etc)?
I ask this because I want the layout and the performance of the device to be consistent across most screen sizes.
There is a regularly updated diagram with the screen sizes and densitys available at the android developers site:
Source
This doesn't tell you an exact resolution, but seperates all phones into 4 sizes (small, normal, large, xlarge) and densities. This should give you a hint at least.
The biggest chunk is obviously Normal/hdpi, I guess that should be a lot of 3.7" HDPI displays with a 480x800 resolution (or at least close to this res). Like the Nexus One or HTC Desire (there are sure some newer ones, but I only keep an eye on the market when I'm searching for a phone to buy).
You can use all resolution to test your application, because some phones have QVGA resolution, some HVGA or WVGA resolution. Tablets have others resolutions.
More informations : http://developer.android.com/guide/practices/screens_support.html
If you use the dp unit for the sizes of your screen elements, then you shouldn't need to worry (as much) as this is a relative size, based on the pixel density of the screen.

Categories

Resources