When are icons generated at runtime? - android

I have an Android app containing about 150 icons for each screen resolution.
If I put all the icons in all 5 major resolutions (ldpi, mdpi, hdpi, xhdpi, xxhdpi), then it will make the total number of icons to 750.
This has several drawbacks:
Big APK size
Slow build process when using dexguard with ant build script. It
does some processing on the images that take some time.
Alternatively I can put icons only in some of the resolutions. For instance ldpi devices are only 10% of the market now, and somewhere in Android official doc they say that Android can efficiently scale down 50% from hdpi icons to ldpi.
Now, if I chose to go this way and not provide ldpi icons, what will be the impact of resizing the icons from hdpi to ldpi at runtime on the Android device? If it needs to resize 150 icons it can take some time, especialy since ldpi devices are likely to have slower CPU.
At which stage does the resizing happen on Android devices: at install time? At first app launch time? At each launch?
Thank you for your suggestions!

When you decompile Google's own APKs they are not using ldpi at all for a time. And they are using xxhdpi only for launcher icon of the applications. xxhdpi icons especially makes the APK sizes bigger.
The resizing of the icons probably done on runtime at each launch.

If the images are used at the layout you can use the xxhdpi images and then you can generate the xhdpi, hdpi, mdpi and ldpi at run time.
Get the Image from the xxhdpi.
scale it to the needed resolution.
use it in your layout.
write it in the disk.
try this to generate thumb at runtime.

Android will nicely* scale down your drawables by a difference of up to 2 density buckets. It looks like crap if you try to do more than 2 buckets (ie. more than a factor of 2). So you should provide every third bucket - currently xxxhdpi and hdpi only.
*Unless you have pixel art in your drawables (but don't do that), where bilinear interpolation won't be acceptable. Then you should pick a minimum supported bucket and provide everything above that.

Related

How to properly create assets and design a screen for Android?

I'm quite new to Android development, and this time, not a programming question on SO, but rather a question about image design on Android.
I'm a bit lost in the densities of the devices.
The goal of my application is to support as much as possible devices.
Now, I own a Nexus 5 device, of which I know that it's a xxhdpi screen with a resolution of 1920 x 1080.
Since it's an xxhdpi device, the scaling factor is 3, so for simplicity, I divide it by 3 which given me the following resolution on mdpi and on mdpi 1px is equal to 1dp.
Therefore, my Android device is 360 x 640dp.
So, I create a new document in InkScape or Illustrator, whatever you want and create my design based on that particular resolution.
Now, I know that on my device the navigation bar is 48dp and the and the status bar is 25dp, which gives me a content area of 360 x 567 dp.
I've found the information about the screens here: http://www.emirweb.com/ScreenDeviceStatistics.php
What I see on this page is that other devices have another status bar height, another action bar height and that the DP's doesn't equal accross various devices.
So, the question is, how can I design a screen of which I'm sure that it will support all the available screens on the market?
Kind regards
Read this carefully
Supporting multiple screens
Edit :
Create designs for phones of hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi densities and test them on emulator.
Extend designs for 7" tablet and test them on emulator.
Move on to 10" tablets.
Use available online tools to test your design on a variety of screens and create specific folders using "New Size Qualifiers" as mentioned in the doc above to support those devices in which you don't see your design properly
Use Android Asset Studio to scale your icons for different screen densities. For backgrounds, create 9-patch version of your images from the same tool. They will also be generated for different screen densities
I think there's no need to care about the height of the ActionBar's height and all. If you put the images of multiple resolution in the respective drawable folders that's enough. e.g. Same image with different resolutions has to be put in drawable-hdpi, drawable-mdpi, drawable-xhdpi etc. That's all you need to do. Android will automatically choose the image from these folder according to device's screen resolution.
I agree #geekoraul that you'll need to read Supporting Multiple Screens first to give you that foundation.
The take away from it is that dp are Android's way of defining a predictable metric to bridge across multiple device densities. The main goal is to scale them correctly so that it still looks consistent.
A basic workflow would be, select a target density (usually hdpi/xhdpi), create your assets, and use tools to create appropriate resources for the other densities.
Some tools are,
Zeplin - You can create you UI and all assets/resources will be generated for you (dimensions, colours, spacing, drawables etc.)
Android Asset Studio - Generates assets like icons, themes and styles

Android UI DPI Issue - is xxxhdpi resources needed?

I am designing an android app for a client. Following the guidelines of Android UI design I have sliced all the icons and images in the following dpi's - xxhdpi, xhdpi, hdpi, mdpi, ldpi.
While the android design guide says they have released xxxhdpi also. Is it necessary to include files with 640 dpi(xxxhdpi) with my app?
Does the app loading time depends on this?
As per Developer site
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.
Check this link for more details http://developer.android.com/design/style/iconography.html

Do we need to add all images with different dpi to Android Apps

As you know Android applications have different DPIs and also in the Android applications we can add drawables with diffrent DPIs in diffrent ldpi, mdpi, hdpi and xhdpi folders.
The question is that when we want to support all DPIs we should add the icons with all different sizes or just with the biggest one?
I mean for example suppose that I have one action bar item with icon. Whether I should add the icon of this action bar item with 24x24(in drawable-mdpi folder),36x36 (in drawble-hdpi folder),48x48 (in drawable-xhdpi folder),.....
Or I just need to add one icon with size 96x96 in xxxhdpi folder and android will set the icon for other DPIs with good quality?
TLDR see the bold below
Different density folders were added later on for Android which means that...
If you wanted to be lazy and just add one asset the best choice would probably be the HDPI asset if your min app target < 8 and XHDPI if its >= 8. This is because the system will scale the resource up and down, but you would still want to start off with the highest resolution possible.
If you want to have complete control over how the assets are scaled then you can by all means provide your own for all / some of the densitys. In practise I generally provide HDPI / XHDPI as above and give all the resource buckets for things like logos / AB icons / App icons etc. I generally find the auto scaling to be pretty good and work for most situations, but will occasionally have to supply and extra LD/MD asset if its a small asset / contains small text etc. Plus if i duplicated all assets for things like XXXHDPI I would get pretty good apk bloat.
You can also use IDEs built in tools to add a single asset for many densitys at once. In Android Studio 0.6 this is File->New->Image Asset and a wizard will appear.
I have never noticed or heard of any perfomance impact of allowing Android to scale assets automatically - presumably this is done in hardware.
It may not look great when auto scaling down to LDPI say so you can optionally provide your own scaled assets for all other densities.
Taken from the link below
ldpi: Low-density screens; approximately 120dpi.
mdpi: Medium-density (on traditional HVGA) screens; approximately 160dpi.
hdpi: High-density screens; approximately 240dpi.
xhdpi: Extra high-density screens; approximately 320dpi. Added in API Level 8
nodpi: This can be used for bitmap resources that you do not want to be scaled to match the device density.
tvdpi: Screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a "primary" density group. It is mostly intended for televisions and most apps shouldn't need it—providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. This qualifier was introduced with API level 13.
List taken from this dev link for more info.
This is the approach I have used on many apps in my professional career including ones for Google & the BBC and not had issues.

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...

how can i develop application for all android devices ? what setting can i put on simulator that work on most devices?

What simulator resolution i should keep when developing application for Samsung galaxy s2 and galaxy s3 ?
What i found that samsung galaxy s2 has 480x800 resolution and s3 has 1280x720 resolution so what i have understood up till now that I should ask my graphics designer to provide me hdpi graphics that contain 480x800 background images and to implement same background image in galaxy s3 mobile, I will use image of size 1280x720 and put in xhdpi folder so that it can work on s3.
The background image is something which covers whole available area for mobile app. so am i right ??
You will need to create several emulators or get various devices.
There are some pretty important ones, so generally you need to make sure you have:
ldpi, mdpi, hdpi, xhdpi
and
small, medium, large, xlarge
Some people choose to exclude certain sizes (like small and ldpi) but htat's up to you,
if you go with some or all of the following, it should be a good start:
480x320 (SE Mini 10), 480x800 (GS2, Desire, etc), 1280x720 (GS3, Galaxy Nexus etc), 1280x800 (Note, Xoom, various other tablets)
HTC ChaCha (because it's landscape default)
You need to make sure you create resources in the relevant folders for each density, usually, I tend to ignore ldpi and just put resources in:
mdpi,hdpi and xhdpi (mdpi will be scaled down for ldpi devices,
automatically)
You may also need to create various portrait and landscape layouts in different sizes.
Reading this page provides most of the necessary information:
http://developer.android.com/guide/practices/screens_support.html
This page also contains important information regarding size distribution and popularity that is constantly up to date:
Android Stats
One thing that Android does for you is that it manages resolution. If you use the proper size formats (dp, sp, etc), your layout will scale to almost all resolutions. If you place images in the proper drawable folders (hdpi, ldpi, mdpi, etc), the OS will also swap those out as necessary.
Also, the emulator should handle resolutions for specific devices, if I recall correctly.
Desing lazout in smart way! Usualy it means don't put to mutch content in one layout.
Make sure that evrything looks good on smallest size and bigest size. It is better to treat tablets separetly. Read how providing alternative resources works, you can build sepereate layouts for each screen size.
Check if the hardware is available on that device before using it. hasSystemFeature() can be used for checking.

Categories

Resources