How can I create Android images with good resolution? - android

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.

Related

HDPI, LDPI, MDPI

Sorry. I have no idea about Android screen size HDPI, LDPI, MDPI. How can I check my flutter app in these screen size?
Create new android emulators with different pixel densities, and run the app on them. I wouldn't worry about ldpi (.1% of devices). The cutoffs are 160 dpi (mdpi), 240 dpi (hdpi), 320 dpi (xhdpi) and 480 (xxhdpi).
Generally this shouldn't be a problem as long as you specified all your sizes in dp rather than pixels. The most likely thing to want to change is images, make sure that any non-vector image looks good at multiple resolutions.
HDPI, LDPI, MDPI all refer to the pixel density of your display and not resolution of the device.
Generally when developing for multiple screen sizes you should focus more on viewport (say 360dp and 600dp as your breakpoints), then find or create new android virtual devices that match your viewport and then run your app on those devices.
Here are a few good links:
Material IO Pixel Density
Android Documentation
Android Device List

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

what are the best qualifieres to uses in 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.

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.

How mdpi, hdpi, xhdpi folder works?

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)
So i got graphics(images) at resolution 320 pixels per inch from designer in these dimension only
480x800 hdpi
720x1280 mdpi
800x1280 mdpi
I am confused which size of images should be placed in mdpi folder, hdpi folder and xhdpi folder. I want to make one application which can work on most android phones and tablets ?
You can create different graphic objects for use at different pixel densities. Android treats mdpi (160 pixels/inch) as the base density. So for mdpi devices, 1 dp = 1 pixel. At higher densities, there are more pixels per inch (240 for hdpi, 320 for xhdpi). Android attempts to make graphic images occupy the same physical dimensions on the screen regardless of the device pixel density. So if all it finds is an mdpi resource, and the device is hdpi, it will scale the graphic by 240/160 = 150%, and it will double the size of the graphic for xhdpi.
If you don't want this automatic scaling (which can make graphics look poor), you can simply supply your own version of graphic resources for use at higher densities. These graphics should be of the same size that Android would scale an mdpi resource.
Note that the pixels/inch that was stored in the image file has nothing to do with this. It's all based on where you put the graphics files in the resources directory for your project. Any graphics placed in res/drawable are assumed to be properly sized for mdpi displays, as are graphics placed in res/drawable-mdpi. Image files that it finds in res/drawable-hdpi are assumed to be properly sized for hdpi displays, etc. When your program runs on a particular device, Android will first look for a graphic that matches the display density of that device. If it does not find one but instead finds one for a different density, it will use that and automatically scale the image based on the above rules.
When you request a resource for which you provide alternatives, Android selects which alternative resource to use at runtime, depending on the current device configuration. To demonstrate how Android selects an alternative resource, assume the following drawable directories each contain different versions of the same images:
drawable/
drawable-en/
drawable-fr-rCA/
drawable-en-port/
drawable-en-notouch-12key/
drawable-port-ldpi/
drawable-port-notouch-12key/
And assume the following is the device configuration:
Locale = en-GB
Screen orientation = port
Screen pixel density = hdpi
Touchscreen type = notouch
Primary text input method = 12key
By comparing the device configuration to the available alternative resources, Android selects drawables from drawable-en-port.
The system arrives at its decision for which resources to use with the following logic:
Ref : How Android Finds the Best-matching Resource
Other References : Density independence , Providing Alternative Resources and Best Practices
And I will say that you should read complete page Supporting Multiple Screens, I don't think nothing will be better documentation than it...
I'm confused myself with all the screen size fragmentation but the basics are:
1. You need to create various folders under layouts to work with your images
2. Images will exist in the drawables folders also under various folders.
3. You should have a basic /layout and /drawable folder to accompany non-specific folders
4. Work from xhdpi then scale images down!
Examples for specific screen folders:
/layout-hdpi
/layout-xhdpi
/drawable-hdpi
/drawable-xhdpi
From what I know:
480 x 800 is hdpi (older phones eg S2, HTC Desire etc)
720 x 1280 is xhdpi (new phones eg S3, Galaxy Nexus etc)
Basically, Depending on the phone, android will grab resources from the necessary folder and if there is none then it will grab from the main '\layout' or '\drawable' folder. For example, the app running on a Galaxy Nexus will grab resources from '\layout-xhdpi' if the folder exists.
yes, you can make one app, but was need creating folders: /res/drawable, /res/drawable-mdpi, /res/drawable-hdpi and add content for all screen sizes

Categories

Resources