I want to create an Android app with ImageButtons that look good, and appropriately-sized, on a wide variety of devices. I'm aware that multiple levels of conditionality can be built into Android drawables, the simplest being to create folders like
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
for different densities of bitmap. However, buttons that look good on an mdpi phone look poky on an mdpi tablet, and I'd rather use the hdpi bitmaps for that application. There is a way to do this using folders named like
drawable-small-ldpi
drawable-normal-ldpi
drawable-large-ldpi
drawable-xlarge-ldpi
drawable-small-mdpi
drawable-normal-mdpi ...
etc. As you can see there are sixteen different folders to cover conditional screen sizes for each density. I can probably reduce this somewhat by using defaults like
drawable-ldpi
drawable-large-ldpi
drawable-xlarge-ldpi ...
but my intention is to use the SAME drawables for large and x-large screens on one density as for the small and normal screens on the density above. I feel that this method is a waste of resource space in the APK. Is there a way to create SINGLE drawable folders that contain images targeted for:
Small low-density devices
Large low-density AND small medium-density devices
Large medium-density AND small high-density devices
Large high-density AND small extra-high-density devices
Large extra-high-density devices?
Alternatively, is there another way to assert conditionality based on device size AND device density?
Taken from http://developer.android.com/guide/topics/resources/providing-resources.html#AliasResources:
"When you have a resource that you'd like to use for more than one device configuration (but do not want to provide as a default resource), you do not need to put the same resource in more than one alternative resource directory. Instead, you can (in some cases) create an alternative resource that acts as an alias for a resource saved in your default resource directory."
Related
I have read many articles on "How to make a responsive app in android" everyone has suggested to use "multiple bitmaps" for each screen. I just want to know that
(1) Can we consider different drawable folders(drawable-hdpi,drawable-xdpi,drawable-xxdpi etc) in-supporting of tablets? or just these folders are designed for smart phones in order to get responsiveness?
In Android you have 2 type of qualifiers for image sizes:
Screen pixel density (dpi): Is the screen resolution. i.e. hdpi, xhdpi, tvdpi.
Screen size: Is the phisical size of the screen. i.e. small, normal, large, xlarge.
Some tablets have big screens, but with low dpi, there so they use images from mdpi or hdpi folder. But you can create special folders for tablets using the screen size qualifier to assign images. For example you can have:
res/
drawable-mdpi/
drawable-hdpi/
drawable-xhdpi/
drawable-xxhdpi/
drawable-xlarge-mdpi/
drawable-xlarge-hdpi/
drawable-xlarge-xhdpi/
drawable-xlarge-xxhdpi/
Your tablet will use the resources from drawable-xlarge- according to the dpi resolution.
To learn more about this refer to:
https://developer.android.com/guide/topics/resources/providing-resources.html
Responsive app is not just about using different Drawables. It contains Layouts and Dimensions too.
I advise you to read these two articles from google :
Designing for Multiple Screens
Supporting Multiple Screens
This question already has answers here:
Android screen size HDPI, LDPI, MDPI [duplicate]
(4 answers)
Closed 9 years ago.
I have to manage different screen sizes and different densities in my Android app.
I am not getting directory structure properly.
What I understand so far is there are four types of screen sizes:
small
normal
large
xlarge
and different densities as well:
ldpi
mdpi
hdpi
xhdpi
Now each device size (small , normal , large and xlarge) shall map against each density. Because every size can have different density, right?
If yes, then we can say small screen have all the density i.e ( ldpi , mdpi , hdpi , xhdpi)
same for normal, large and xlarge.
The point is how I'll manage them in my drawable directories.
Will there be four folders for small screen size with different size (drawable-small-ldpi, drawable-small-mdpi, drawable-small-hdpi, drawable-small-xhdpi)?
And same for other screen sizes as well.
If not then how I'll manage all the image in ( drawable-ldpi , drawable-mdpi , drawable-hdpi , drawable-xhdpi) folder because different screen size I'll have different size of images. Then how can a small device with different density and large device with a different size be manageable in same density folder.
Please don't give me reference of any Android document as I read all that stuff.
If any one can't get my point, then please let me know. I'm very confused.
When I have started development in Android, I was confused about same issue.But now I have figured it out and I'm doing pretty well.
Anyways, You are absolutely right.you can provide different images by 4 folders for each.i.e.: drawable-small-ldpi, drawable-small-mdpi, drawable-small-hdpi, drawable-small-xhdpi
But it is just waste of your time.because you don't need to worry this much about it.Android can scale up/scale down according to the device configuration.so just provide extra images for those devices only if you don't get desired outputs for them.
As far as I know, supporting multiple devices, you have to consider few general criteria in your mind.
Density qualifiers: ldpi,mdpi,hdpi,xhdpi,etc are generally used when you want to provide different resolution images.
Size qualifiers + Orientation qualifiers: small,normal,large,xlarge,sw600dp,normal-land,normal-port,etc are generally used when you want to provide different layout designs.
i.e.: single pane layout,multi-pane layout,different elements in layouts according to different screen sizes.
For reference: Download the example app from here and try to understand how it is being supported for multiple screens.
I hope it will be helpful !!
Here are official docs for you to read about the subject: Supporting Multiple Screens then Supporting Different Screen Sizes
Put your all image in all different folder that is drawable-hdpi, drawable-ldpi, drawable-mdpi, drawable-xhdpi and drawable-xxhdpi. android will take care of it.
What I always do is just put all my images in one folder (usually xhdpi). The Android system will scale them for you so you don't have to worry about what to put in what folder.
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
Perhaps we use one image for all ldpi, hdpi, mdpi and xdpi where we need to keep the image(in which folder). This is a bit confusion to me. Can anybody clarify my confusion?
Just keep it in res/drawable.
This is not recommended as the images you use will then not scale well for different device screen sizes. But if you place an image in res/drawable this will work.
Instead of creating all of the different folder buckets, drawable-ldpi, drawable-hdpi, etc. Just create one folder, drawable, and then put your images in there and when Android searchs for the image and doesn't find the other folders it will default to the drawable folder as the only resource. This folder is understood by Android to be equal to the drawable-mdpi and will scale the images accordingly.
EDIT: Also available is the res/drawable-nodpi, This will not scale your image at all and it will retain the same size on all screens.
Take a look at How to Support Multiple Screens
The "default" resources are those that are not tagged with a configuration qualifier. For example, the resources in drawable/ are the default drawable resources. The system assumes that default resources are designed for the baseline screen size and density, which is a normal screen size and a medium density. As such, the system scales default density resources up for high-density screens and down for low-density screens, as appropriate.
So yes, drawable folder is what you are looking for.
I have written an android application, but I find that the graphic of app has different performance in different size of android phones. Some graphics will even become very bad in Tablet. Hence, I would like to know how to adjust the code of program so that the app can adapt difference size of android phone and tablet automatically. Thanks!
There are two important parameters which needs to taken cared when you are designing an app which
should run on multiple devices:
size(physical size of the device)
density of the device
Size: Size of a device in android is not defined as a unique physical value but as a range.
These are: small, normal, large and xlarge.
Density: Density is also defined as a range.
These are: ldpi, mdpi, hdpi and xhdpi.
For handling size you need to use have multiple layouts, one for each category of the size and you need to use different dp value for the height and width of the views for each of the layout as the sizeof a small and a large device will not be same.
For handling density you need to using different drawables for different screen densities i.e you need to place different density drawables in different drawable folders.
Eg:
These are the resolutions for a particular drawable
36x36 for low-density (placed in drawable-ldpi)
48x48 for medium-density (placed in drawable-mdpi)
72x72 for high-density (placed in drawable-hdpi)
96x96 for extra high-density (placed in drawable-xhdpi)
The ratio for this variation of the resolution is 3:4:6:8(ldpi:mdpi:hdpi:xhdpi)
For further reading you can refer to this android developer's link:
http://developer.android.com/guide/practices/screens_support.html
Use Relative Layout
Prepare Graphics for every density (ldpi, mdpi, hdpi, xhdpi)
Nine patch your graphics.
Use WaitSum in xml layout.
Waitsum is automatically set layout and views in different size density.
I have created four versions of my launcher icon for ldpi, mdpi, hdpi and xhdpi devices. They are of dimensions 36x36, 48x48, 72x72 and 96x96.
I'm wondering what will happen when using a large screen. Consdering large screens are rouglhy 7" + in size a ldpi, large screen will surely not want a 32x32 icon image, located in a drawable-ldpi folder.
I cannot find anything on the dev guide that indicates what icon sizes to assign to large and xlarge devices. Presumably I would put a larger copy of the icon in the drawable-large and drawable-xlarge folder. However, I do not know what sizes to use. Does anyone have any recommendations?
Google provide an online tool called Android Assest Studio which creates the launcher icons in the correct size for you. http://android-ui-utils.googlecode.com/hg/asset-studio/dist/icons-launcher.html
A 7-10" tablet doesn't need anything unusually large. You don't need anything bigger than a 96x96 launcher icon for this use case. There is a table in the Launcher Icons section of the design docs that shows which sizes correspond to which densities.
Have a look at the Declaring Tablet Layouts section of the design docs for more info on how to organize resources for 7-10" screens. (Note that the resource used will depend on the screen density, it is possible that a 7" tablet will have an mdpi screen.)