what are the best qualifieres to uses in android? - android

Android runs on a variety of devices that offer different screen sizes and densities. For applications, the Android system provides a consistent development environment across devices and handles most of the work to adjust each application's user interface to the screen on which it is displayed. At the same time, the system provides APIs that allow you to control your application's UI for specific screen sizes and densities, in order to optimize your UI design for different screen configurations. For example, you might want a UI for tablets that's different from the UI for handsets.
This leads us to this question what are the best qualifiers to use from the list bellow:
A set of six generalized densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
Or
sw600dp
sw720dp
w720dp
w1024dp
h720dp
h1024dp
or
A set of screen size :
small
normal
large
xlarge

I suggest to use
sw600dp
sw720dp
w720dp
w1024dp
h720dp
h1024dp
because with those you can control exactly how it looks, while making it easier for you quickly tell the values.
In addition, this is the more "modern" way of defining sizes.
From developer.android.com:
One of the difficulties developers had in pre-3.2 Android devices was
the "large" screen size bin, which encompasses the Dell Streak, the
original Galaxy Tab, and 7" tablets in general. However, many
applications may want to show different layouts for different devices
in this category (such as for 5" and 7" devices), even though they are
all considered to be "large" screens. That's why Android introduced
the "Smallest-width" qualifier (amongst others) in Android 3.2.
The Smallest-width qualifier allows you to target screens that have a
certain minimum width given in dp. For example, the typical 7" tablet
has a minimum width of 600 dp, so if you want your UI to have two
panes on those screens (but a single list on smaller screens), you can
use the same two layouts from the previous section for single and
two-pane layouts, but instead of the large size qualifier, use sw600dp
to indicate the two-pane layout is for screens on which the
smallest-width is 600 dp.

Related

How to desgin an UI which will work on multiple screens?

So I have two phones Note 3 (5.7in 1080p) here is a screenshot of the app:
And I also have A7 2018 (6in 1080x2220 18.5:9) here is a screenshot:
After seeing the massive difference how can I make stable UI across multi-screen sizes and resolutions, and what makes the situation even worse is Android Studio's preview lack of precision.
like is there any way to create something like separate XML layouts for separate classes of display?
This link from the official docs will help you.
Things you can do to support different screen sizes are:
Avoiding usage of absolute values
If you use absolute values, use dp for sizes and sp for font sizes
Use match_parent or wrap_content whenever possible
If you use a ConstraintLayout Guidelines will probably be your friend (can create them % based)
If nothing of the above helps, create a seperate layout for a different screensize (explained here)
It's either use ConstraintLayout with GuideLines or use different layouts for different screen sizes.For example, you can create a layout named main_activity that's optimized for handsets and tablets by creating different versions of the file in directories as follows:
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
Here's how other smallest width values correspond to typical screen sizes:
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a large phone screen ~5" (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
Check out the docs:
https://developer.android.com/guide/practices/screens_support#DeclaringTabletLayouts

Image resolutions for iOS and Android apps

I am creating an application in Xamarin forms both both iOS and Android which will also have images in it. I have two questions.
Can I have one image and use some API calls to modify the resolutions based on the device.
If not, what are the different resolutions needed, for targeting iOS and Android devices both phones and tablets
You certainly could, but this could slow down performance especially if you are loading a lot of images and need to resize often.
I believe it is better to pre-supply images at the correct resolutions. Both Android and iOS have good mechanisms for doing so and the way to do it is identical in Xamarin as in a native app project.
In iOS you can add an image set to your asset catalog for each image you will use and the three different resolutions for that image will go in that Image set, helping to keep things organized. There are no set resolutions, but you would want 1x, 2x and 3x versions where 1x is the "base" version that will be used on non-retina devices, 2x should be double the resolution of 1x and will be used on retina devices, where 3x should be 3x the res of 1x and (I believe) will be used for the 6 Plus and 7 Plus iPhone models.
For Android, it gets a bit more complex, but basically you provide multiple resource image folders (usually named "drawable" but can also be "mipmap") with screen density qualifiers in the names of the folders, e.g. drawable-hdpi or mipmap-hdpi. See this Android document for more info:
https://developer.android.com/guide/practices/screens_support.html
Here are the screen density qualifiers you can use:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
Again the actual size of the image is up to you, but the resolution of, e.g. the mdpi version would want to be ~30% larger that the version in the ldpi folder and so on.

Android Form Factor Metrics

I cannot find the answer to this question anywhere on or off stack overflow:
Google defines common sizes and densities for devices as follows:
Sizes:
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
Densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
My question is:
Which of these sizes corresponds to mobile phone devices? None of the sizes are portrait (height > width).
Say you are trying to figure out what dp to make a full screen bitmap to accommodate all mobile devices...
Generalizing a lot:
For phones (in portrait mode, width by height)
ldpi was typically 240 by 320
mdpi was typically 320 by 480
hdpi is typically 480 by 800 or 480 by 854 and lately 540 by 960
xhdpi is typically 720 by 1280 or 800 by 1280
xxhdpi is typically 1080 by 1920
xxxhdpi is typically ? by ? // who knows that? Feel free to edit, if absolutely sure.
For tablets, it's totally different.
But you asked for phones only.
You can't make best bitmap for all devices.
Many manufacturer set density via build.prop file ro.sf.lcd_density
so tablet could act like phone.
It's better to get current device values with getResources().getDisplayMetrics() and go with it.
You can set ImageView as background and continue with cropping options:
ImageView.ScaleType
After reading the Supporting Multiple Screens Android documentation several times over, and brainstorming a lot, I believe I have identified a couple of ways Google would like developers to generally go about this.
Legacy Solution:
Primarily, they wanted developers to use these small, normal, large, xlarge size qualifiers for drawable/ resource directories to allow Android to pick the correct resource to use.
I think the important thing to notice here, and I could be wrong, is that maybe they originally didn't want developers to have worry about whether the dimensions for these small, normal, large, xlarge sizes apply to a phone or tablet, but rather know they apply to both.
The caveat with that, of course, is that a full-screen image with landscape dimensions (width > height) will not look the same on a portrait device (height > width).
The solution using the legacy method would be to use an ImageView and set it's ScaleType appropriately, so it crops your tablet-sized image on mobile devices.
But there is another possible solution...
Alternate Solution:
There is a also a section on "New Qualifiers" for supporting different screen configurations. In this section, Google details qualifiers such as smallestWidth or available width, that could in theory, be used on your drawable/ resource directories to define proper portrait or landscape resources for your available device width.
For those familiar with web development, these qualifiers are the equivalent of CSS media queries.
As for specific widths to use, Google details some typical configuration examples:
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800
hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
The only doubt left in my mind is that all of their examples use these qualifiers for layout, but not drawable resources. It begs the question whether this is the defacto solution they want developers to use for the given problem.

Android: Getting confused with density per pixel and qualifier on android folders

I have a bit confused with the qualifier. I am dealing with kindle fire 7" and 8.9, galaxy s4.
Kindle Fire 7inch: I need to use values-large-hdpi instead of values-sw600dp in order to work.
Kindle Fire 8.9inch: I can use values-sw600dp not for values-large-hdpi.
Galaxy s4 what qualifier should I use.
the qualifiers refer to what the screen dimensions are. So values-large-hdpi will apply to screens that have a minimum density of hdpi and are classified as a large screen type. The sw600dp means that the in order to use those values the screen must have a minimum width of 600dp. So my guess is that the Kindle Fire 7 inch does not meet the sw600dp requirments (Try holding it in landscape, that might work). But the 8.9 inch (being larger) would meet these requirements. The Galaxy s4 my guess falls into the xhdpi density range, not sure about screen size. Most phones will use normal, but the s4 having such a large screen might qualify to large. I would recommend using a screen width quantifier anyways, as just using hdpi or large is to vague.

How can I create Android images with good resolution?

I'm creating an Android application. The main activity layout will have a background image that will wrap with the whole screen. What resolution should I use to create the background image? What about DPI? I need it to be compatible with all devices
(for example the HTC Sensation screen's resolution is 540 × 960 pixels).
The best way for you is to start reading this article, it contains the best practices for supporting multiple screen sizes and densities.
EDIT:
I use the following directories to store the drawables for maximum size and density optimization:
Small screens support
drawable-small-hdpi
drawable-small-ldpi
Normal screen support
drawable-normal-mdpi
drawable-normal-hdpi
Large screens support
drawable-large-mdpi
Tablet screen support
drawable-xlarge-mdpi
Of course not every time this solution is the best, aqs's solution is more common used. You can follow this site to track which screen sizes and density's are most used and decide which of the screens worth support for your application. And of course you can read about the Providing Alternative Resources to understand better what are your options.
You should read Supporting multiple screens. You must define dpi on your emulator. 240 is hdpi, 160 is mdpi and below that are usually ldpi.
Extract from Android Developer Guide link above:
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
IMHO answer of #Cata is a bit misleading because of mixing screen size and screen density for providing graphics.
I think the best practice is to distinguish this two things by providing:
different size images (PNGs) for different densities and
different layouts for different generalized screen sizes.
By doing so developer can reduce number of different images to 4 categories (ldpi, mdpi, hdpi, xhdpi) if he wants to support all currently existing densities. Of course XML layouts files for different (small, normal, large, xlarge) screen sizes are necessary if we support them but it is much easier to make/edit/correct/adjust xml files than PNGs.
A bit more details and explanation u can find in my previous answer about this topic on this link.
Hope u find this answer useful. Cheers.

Categories

Resources