Setting drawable folder to use for different resolutions
How do I force the Nexus to use resources in drawable-xhdpi and then
the 10 inch tab to use drawable-xxhdpi?
You can't.
The qualifiers hdpi,xhdpi,xxhdpi
describes the screen density of the device, not the size of screen.
From the official doc
Screen density
The quantity of pixels within a physical area of the screen; usually
referred to as dpi (dots per inch). For example, a "low" density
screen has fewer pixels within a given physical area, compared to a
"normal" or "high" density screen. For simplicity, Android groups all
actual screen densities into four generalized densities: low, medium,
high, and extra high.
If you want to support tablets also, use large, xlarge
qualifiers. Nexus 7 is a large-hdpi
tablet(technically it's tvdpi
, but takes images from hdpi
). So if you want to put images for Nexus 7, make a folder named drawable-large-hdpi
and put the images there.
Note: This is the special case for Nexus 7. Because even though Nexus 7 is a 7 inch tablet, it has resolution of 1280 * 800. So it's an hdpi
device. But normal 7 inch devices have lower resolutions of 1024 * 600. So they are mdpi
devices. So the drawable qualifier can change. (From my own experience, first put a folder drawable-large-mdpi
for 7 inch devices and check it on Nexus 7. If there is no problem with images, you dont have to put another folder. Because if a particular folder is not present, Android will check for the nearest possible folder and optimize it for the device screen)
Now regarding the 10 inch tablets case, they are xlarge
devices and their densities can change from mdpi
to xhdpi
(Nexus 10). But many have resolution of 1280 * 800 and they are mdpi
devices.
The better practice is to put the following drawables
// for Phones
drawable-ldpi
drawable-mdpi
drawable-hdpi
//for 7 inch tablets
drawable-large-mdpi
drawable-large-hdpi(for Nexus 7)
// for 10 inch tablets
drawable-xlarge-mdpi
Android Studio: Drawable Folder: How to put Images for Multiple dpi?
The standard procedures are:
- Choose Project > app > scr > main
- Right click "res", choose "New" and choose "Android resource directory"
- In the opened dialog, at Resource Type choose "drawable"
- In the list Available qualifier choose Density, then click the right arrow at the middle.
- Choose the Density that you like then press OK
drawable folders - What resolutions do I need
These are the resolutions in dpi:
ldpi: 120 dpi
mdpi: 160 dpi
hdpi: 240 dpi
xhdpi: 320 dpi
xxhdpi: 480 dpi
xxxhdpi: 640 dpi
You have to calculate the dimensions in pixels basing on the resulution:
Scale factor:
ldpi: 0.75
mdpi: 1.0
hdpi: 1.5
xhdpi: 2.0
xxhdpi: 3.0
xxxhdpi: 4.0
You COULD have all the images in the xxxhdpi folder and let Android scale them down... but not always you'd get nice results (Android scaling DOWN is good, but not as good as pre-sized images).
Nowadays I guess that an xxhdpi resolution is enough, but tomorrow...
It would be scaled UP on an xxxhdpi screen, with not-so-good results (visible pixellation).
A solution would be using svg graphics (which is a vectorial standard based on xml), but you'd need an external library (there are several open source / free - you choose the one which fits best) to render them in a standard control.
Drawable folder different screen resolution issues
you can use drawable-large for tab
Different image sizes for resolution-specific Drawable folders
What you're looking for is the scale-factor for each folder. This works by taking the mdpi
folder as the "base" scale of 1.0.
Scale-factors for each folder are as follows:
- ldpi > 0.75
- mdpi > 1.0
- hdpi > 1.5
- xhdpi > 2.0
- xxhdpi > 3.0
- xxxhdpi > 4.0
So, for example, taking a 48*48px image as your base mdpi image, you'd end up with 32, 48, 72, 96, 144 and 192px images.
Fore more detail, including the source for each of these values, check out shoe-rat's excellent answer from which I sourced much of this one.
Drawable folders for high resolution handhelds
Well, as I said above I can't find any handhelds with Android on it that's got a resolution of 640x960. So I based all my images on 720x1280 instead and put the 640x960 resolution stuff in a large-hdpi folder.
Now my app looks great on the latest Nexus, the Galaxy S3, HTC One-X and all of the other newer hires models. I think the tablets when looking for resources will go for large first, then hdpi where they will find the 2x scaled images.
This is what I ended up with:
xhdpi: 720x1280
large-hdpi: 640x960
hdpi: 480x640
mdpi: 320x480
ldpi: 240x320
Related Topics
Sniffing/Logging Your Own Android Bluetooth Traffic
Android:Static Fields and Memory Leaks
Which Correct Flag of Autoconnect in Connectgatt of Ble
Android:Locationmanager VS Google Play Services
Android Notification Is Not Showing
Programmatically Relaunch/Recreate an Activity
Android - Save/Restore Fragment State
Set Edittext Digits Programmatically
Simple Example for Intent and Bundle
Actionbarsherlock + Tabs + Multi Fragments
How to Show Multiple Markers on Mapfragment in Google Map API V2
Android:Call Activity of Another Application
Progressdialog Is Deprecated.What Is the Alternate One to Use
Convert Arraylist<Mycustomclass> to JSONarray
How to Use Onsaveinstancestate() and Onrestoreinstancestate()