How mdpi, hdpi, xhdpi folder works? - android

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

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

Android xxx-hdpi real devices

I'm gonna release my app, it's a 1.2Mb apk that includes about 120 icons in 4 different formats (ldpi, mdpi, hdpi, x-hdpi).
If I add xx-dpi and xxx-hdpi icons the apk grows bigger and loading time increases.
There are many entry-level devices out there with really loooow memory and I'd like my app to run everywhere.
Do I really need to add xx-hdpi?
And is there a real device that requires xxx-hdpi?
You shouldn't really need xxxhdpi. It was only introduced because of the way that launcher icons are scaled on the nexus 5's launcher
Edit
Back when I answered in Jan 2014, the Nexus 5 was the only device using xxxhdpi. Now many devices including the Nexus 6 and LG G3 use it. So it would be a good idea to include it in your app.
We had to add xxxhdpi to our app for the Nexus 6, LG G3, and Samsung Galaxy Note 4. There will be more xxxdhpi devices in the future.
You do not need xxxhpdi for most of your images. You only need xxxhdpi for your launcher icon. Please see http://developer.android.com/guide/practices/screens_support.html
You should not use the xxxhdpi qualifier for UI elements other than the launcher icon.
It's pretty clear in the above quote. In the example folder layout they give, they show all the densities for the res/drawable folders up to -xxhdpi, but then they show the res/mipmap folders up to -xxxhdpi. Here are more quotes:
xxxhdpi Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi). Use this for the launcher icon only, see note above.
The mipmap-xxxhdpi qualifier is necessary only to provide a launcher icon that can appear larger than usual on an xxhdpi device. You do not need to provide xxxhdpi assets for all your app's images.
You don't need ldpi, because Android downsizes hdpi to ldpi.
From https://developer.android.com/design/style/iconography.html
Note: Android also supports low-density (LDPI) screens, but you normally don't need to create custom assets at this size because Android effectively down-scales your HDPI assets by 1/2 to match the expected size.
From Android iconography documentation itself:
Some devices scale-up the launcher icon by as much as 25%. For example, if your highest density launcher icon image is already extra-extra-high density, the scaling process will make it appear less crisp. So you should provide a higher density launcher icon in the drawable-xxxhdpi directory, which the system uses instead of scaling up a smaller version of the icon.
Note: the drawable-xxxhdpi qualifier is necessary only to provide a launcher icon that can appear larger than usual on an xxhdpi device. You do not need to provide xxxhdpi assets for all your app's images.
more on: http://developer.android.com/design/style/iconography.html
I don't know if there is a device that requires xxx-hdpi, but xx-hdpi is not yet used very often. But the same goes for ldpi, almost no device still requires ldpi. If you just do mdpi, hdpi and xhdpi, it will be just fine. If a device requires something bigger or smaller android just scales it to the right size.
Heres what Android says about this:
Provide different bitmap drawables for different screen densities
By default, Android scales your bitmap drawables (.png, .jpg, and .gif
files) and Nine-Patch drawables (.9.png files) so that they render at
the appropriate physical size on each device. For example, if your
application provides bitmap drawables only for the baseline, medium
screen density (mdpi), then the system scales them up when on a
high-density screen, and scales them down when on a low-density
screen. This scaling can cause artifacts in the bitmaps. To ensure
your bitmaps look their best, you should include alternative versions
at different resolutions for different screen densities. The
configuration qualifiers you can use for density-specific resources
are ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high).
For example, bitmaps for high-density screens should go in
drawable-hdpi/.
You can find the documentation here:
https://developer.android.com/guide/practices/screens_support.html
Hope this helps
I think you should focus on the most popular screen densities, which are hdpi, xhdpi, and xxhdpi. See this link for the current worldwide average distribution of each density.
Forget Everything & make it Simple !
Just store highest resolution images in only one folder. Either in drawable-hdpi, & delete other images from the rest drawable folders.
I have tested it in various devices & it works like a charm...

Android does not access xhdpi folder for tablet view

I have both hdpi and xhdpi folders in my res folder. However, android makes use of hdpi xml file for 1280 X 800 resolution of a tablet. Could it be because my xml file accesses resources which are in drawable-hdpi folder but not in drawable-xhdpi folder?
I think you are confused with DPI vs screen sizes, which resolution along does not provide. You can have a XHDPI device with a small screen that is very high resolution (such as the Galaxy S3) or a MDPI or LDPI device with a very large screen (such as when you use Android on your TV).
Generally speaking, Dot per pixel = Resolution / Screen size.
Not all android devices are set to the right density by the manufacturer, its really a hodgepodge of densities no matter what resolution you think you have, the device could still be seen by the android OS as a lower or different density than you think
if the android OS thinks your device is HDPI then it will access HDPI drawables

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.

Android: Optimize for high-dpi devices only but still support (small- and) medium-dpi screens

I'm building a game with graphic assets in hdpi resolutions (hence I put the files in drawable-hdpi directory). I don't want to have a corresponding mdpi resolution of the images, and I will code everything in 240-dpi based pixel coordinates.
Is it possible to still allow mdpi and ldpi devices to run the app, by automatically scaling the graphics from the hdpi version?
If you put the graphic assets in drawable (with no qualifier) they will be used by all 1.6+ phones and scaled as appropriate for the screen resolution of the phone. You only need to use hdpi if you want to provide different assets for different screen densities.
You should put the assets in the drawable-hdpi/ directory. Phones will scale them down automatically with the following ratio:
3:4:6:8
l m h xh
So your hdpi assets would scaled 3:2 on a mdpi device. If you only put them in the drawable/ directory, the system uses mdpi as a baseline, and your assets will actually be scaled up on hdpi devices.
Note: If a density qualifier is not defined in a directory name, the system assumes that the resources in that directory are designed for the baseline medium density and will scale for other densities as appropriate.
How to Support Multiple Screens
How Android Finds the Best-matching Resource

Categories

Resources