Why are my project's drawables blurry? - android

For some reason, the drawables in my app are blurry. This is especially apparent in menus when I put built-in system icons side-by-side with icons from my project's res folder.
Here's an example. The left envelope icon is in my app's drawable-hdpi folder. It is scaled down, for some reason. The right one is using the built-in Android resources. As far as I can tell, they are the same 72x72px file--I copied the png straight from the drawable-hdpi folder in SDK to my project's drawable-hdpi folder.
Is there some special setting for drawables in my app that I'm missing?

Try adding the appropriate supports-screens element to your Android manifest, and make sure you have a min-sdk of at least 4. Also make sure your uses-sdk element is nested under the manifest and not under the application (if it's in the wrong place or missing, your app will still work but can cause issues with compatibility-related code like resource scaling, and will prevent uploading to the market with an obscure error... it can be a tough one to track down).

Are you using an mdpi screen? If so then your device is having to take the drawables from drawables-hdpi and scale them down, which would likely cause them to blur.
You might try also copying the -mdpi resources to your drawable-mdpi folder, which would allow the framework use your drawables without adjusting for screen density.
Edit - now that I think about it, I'm not sure why your image would appear smaller unless your screen had a greater dpi than hdpi.

Related

App Crashes. Error Inflating XML. Cant find image because xxxhdpi folder is not there

Switched my eclipse project to Android studio. I was maintaining resources under drawable-mdpi folder only. Now in studio the preview of XML loads images correctly. However when I run the app in a device with resolution higher than mdpi the app crashes, shows error inflating binary XML.
After a long analysis I found the issue that the device was trying to load images from its corresponding density folder which is not available. So I created the folder drawable-xhdpi and put images in that folder. Now the app works fine.
Why android studio can't pick image from other density drawable folder and resize which is possible by eclipse. I can't maintain 5 different drawable folders because there are lots of images.
you have to add "drawable-hdpi" resource directory and paste all the hdpi resources there because currently 70% android devices supports hdpi resolution images.
if you only maintain the hdpi, then it is also ok.
android manages all remaining resouces from hdpi resouce directory.
Android application resource directories provide different layout designs for different screen sizes and different drawables. These different drawables are used by android to support a major range of all the android devices present out there. It's a standard practice to put your resources considering these densities. Coming back to your query:
Why android studio can't pick image from other density drawable folder and resize which is possible by eclipse. I can't maintain 5 different drawable folders because there are lots of images.
For your case,In order to maintain this you could create a drawable with nodpi and put your all resources there. nodpi focus resources for all densities.Your resources should be density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.
Hope this will clear your doubts, for more insight you can also look this.
you don't need to add all images to each difference size folder but depending the size of the image you might need to add images to different folders.
simple example is this can occour once you add high res/size images in normal drawble folder
Skipped 100 frames! The application may be doing too much work on its main thread.
This might not crash your app but will make it's performance down.
and
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 : https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
Do we need to add all images with different dpi to Android Apps

How to specify icons for different densities screen?

While working on an app, I noticed that there are different files such as drawable and drawable-hdpi. So I found out that these folders are for different icons and images size. My problem is that these two are two separate folders and I was wondering if I have to direct the android to the icons in the separate folder?
By that I mean do I have to first figure out what kind of dpi the device is and set the appropriate icons or can I just declare one drawable resource and android will figure it out for me?
If I can just set an icon name and the drawable file and the android system will know what to use for the different screen, then can you explain to me how this is done? I mean it is two separate files drawable and drawable-hdpi. So how can just set an icon image in the drawable folder and android knows what to access for the drawable-hdpi for the different device?
There are several questions bundled in one, but I will explain all of them in detail.
As you know, there are a variety of Android devices with different screen sizes. That is why, they are separated into a few categories based on their density. Must read this, if you haven't already.
This is the full classification,
So the idea is to have all these directories separately and not just a single "drawable" folder. Whenever you want to put any image or icon in your app, you need to put different sizes of them in their respective directories correctly.
two separate folders and I was wondering if I have to direct the
android to the icons in the separate folder?
You do not have to direct Android to do anything. Android will automatically pick the right image size from the "drawable-**dpi" intelligently.
By that I mean do I have to first figure out what kind of dpi the
device is and set the appropriate icons or can I just declare one
drawable resource and android will figure it out for me?
You can't figure out dpi of all devices, as your app will run on several devices having different densities. You just need to put different sizes of your icons in their respective drawable directory.
You should never put a single image or icon in the "drawable" directory as it can drastically slow down your app as Android need to dynamically resize your images at runtime.
If I can just set an icon name and the drawable file and the android
system will know what to use for the different screen, then can you
explain to me how this is done?
Just refer to the previous question, its already answered.
So how can just set an icon image in the drawable folder and android
knows what to access for the drawable-hdpi for the different device?
As explained earlier, Android obviously knows which device the app is currently running and thereby knows its screen density. Now it is very easy for Android just pick the right image based on the current screen density if you have put them properly in their respective drawable folders.
UPDATE
Just to answer your new question.
You start out with one "drawable" folder. But you need to create the other directories yourself and they need to have the proper name like drawable-mdpi, drawable-hdpi, drawable-xhdpi, etc.
You cannot have any other name like drawable-K or drawable-l, or not even a spelling mistake in the names. Android just scans to see if the folders with these names exists in your app, if so, then it will pick right one.
Suppose you are using a Nexus 5 which is an xxhdpi device,
i) Now Android will look for the drawable-xhdpi directory in your app for a particular image.
ii) If it exists, then it will just pick it up. If it doesn't then it will look for the nearest ones like drawable-xxhdpi or drawable-hdpi and resize the image slightly to fit.
iii) If nothing exists, then it will pick the image from the raw "drawable" folder.
Hope it clears all your doubts.

LG G3 doesn't use image from xxxhdpi if there are alternatives — as a result, image is blurred

Say, I have an ImageView with both sizes set to wrap_content, and it has some image: android:src="#drawable/xyz".
If this image appears only in xxxhdpi folder, then everything is fine. However, if it appears in any of the other drawable directories (xxhdpi, xhdpi, hdpi, mdpi, or even sw320dp), then it doesn't use the image from xxxhdpi and, as a result, the image is blurred. (it's not easy to notice, but I can notice this and I don't think QHD displays make any sense if their full resolution is not used)
Is it possible to solve this issue without resorting to multiple APKs?
More precisely, this is LG D856 phone (dual SIM), with Android 4.4.2.
update
This is weird, but if I create project in Android Studio instead of this tool for coding for Android in Scala, then there's no such issue…
update 2
APK file: http://dropbox.com/s/lqdj9w7iimh2gj9/magicgoose-example-debug.apk?dl=0
Source code: http://dropbox.com/s/cs4pngpkvkoe5q2/dpi-example-src.zip?dl=0
Source can be built using SBT (scala build tool)
I'm using this plugin: https://github.com/pfn/android-sdk-plugin
read here:
http://developer.android.com/design/style/iconography.html
Provide an xxx-high-density launcher icon
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.
I know for some cases you really wish it used the xxx but what I understand for this text is: "Android only uses xxx for the launcher icon and nothing more." So I believe you'll have to find some work around (e.g. set a bigger PNG and scale it down on the ImageView, or mipmaps) until Android as a platform uses the triple X everywhere.
The problem was in that the plugin did set target API level to 1 by default. When I set it explicitly to 21, the problem is gone.

Android drawable folder image size

I am pretty new to Android and I am doing a pet project in order for me to learn Android. Basically I want to display six images on the screen. I have noticed the drawable folders and I have 256x256px inages in the drawable-xhdpi folder. In the Nexus 5 preview in android studio it looks great but in Nexus 7 (2012 version) the images are very small and both Nexus 5 and Nexus 7 are using the drawables-xhdpi folder.
This is my code:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageMars"
android:id="#+id/imageJupiter"
android:src="#drawable/jupiter"
android:contentDescription="#string/content_desc_jupiter"
android:layout_toRightOf="#+id/imageVenus"
android:adjustViewBounds="true"/>
How can I make the images look bigger on the Nexus 7, but without being to big for the nexus 5?
And I want the application to look good on other devices too, so I don't think that setting a fixed size for the image(70dp x 70dp for example) would work
Thank you
Best practice in Android is to provide the correct size images in each of those folders and let the system choose the best one based on the device. Supporting Multiple Screens is a must read.
Basically what happens is the system will navigate to the folder that would best satisfy its screen, if the image it needs is there, great; if not it will navigate to the next best folder and so on. If it cannot use the best for the device it will use the best you gave and try its best to make it look as good as possible. Sometimes this isn't so great. It can stretch or shrink images into an ugly state.
So again, the best thing to do is provide multiple sizes of the same image in each of the folders to get the desired results.
Edit (response to commentary):
Guess not. In Eclipse/ADT I've got
Nexus 4 # 768x1280 - Normal xhdpi
Nexus 7 (2012) # 800x1280 - Large tvdpi
So regardless of "larger" the fact remains that they're pulling resources from different drawable folders. The tvdpi is said to be not needed in most apps because it's somewhere between mdpi and hdpi and those folders are usually sufficient. Maybe add the tvdpi and see if it varies at all and make sure you've correctly scaled your images based on the folder.
Edit:
Alright, the behavior you're experiencing is normal - unfortunately I suppose - but I found a solution. I've personally never faced this because I learned it's better to utilize the extra area on larger screens to put more content on there.
Anyway, as if you didn't have enough drawable folders, you need another drawable folder, or three, along with more images - yeah!
In my previous edit I mentioned the "Normal" and "Large" modifiers of the drawable folders as they appear in Eclipse ADT. Well, it turns out that those are valid folders as well and certain devices with small, large, or xlarge screens will use them.
I was able to get larger images by adding another res directory titled drawable-xlarge-xhdpi; this is for the Nexus 10. I enlarged your jupiter file to 512x512 and...
Note: I read that this isn't a recommended solution but could not see anywhere in the Android docs that warned against it. Research may be necessary!
You should provide different image sizes for different display sizes/resolutions. That what the drawable-100w, etc folders are.
If you don't want to do that but you still want the images resized to use all the available space, you will have to do resize the ImageView elements programmatically.

App crash on devices with ldpi screens

I created an app with images, and I added them via Android Icon Set wizard. The wizard created 3 versions for the images - mdpi, hdpi, xhdpi.
I published my app on google play, and I got a crash reports from users that have ldpi screen. The exception was Caused by: android.content.res.Resources$NotFoundException: File from drawable resource ID #0x7f02007f.
The drawable was exists in mdpi, hdpi and xhdpi and the app worked to the rest of the users.
So I guess that the problem was that the drawable dose not exists in its ldpi version.
So my questions are:
1) Is there any way to say to the app to auto scale the mdpi drawables instead of crashing?
2) For support ldpi screens, must I edit the images to ldpi size?
Thanks.
This is a common error of different densities management, so these are the answers to your questions.
1.- No, in the way your assets are stored but Yes, "ONLY if your asset is in a lower hierarchy of your current density" for example: If you have assets in drawable(default non specific density) and drawable-ldpi AND you run the app in a Medium Density Device, the OS will try to resize your Images from -ldpi to your density (if using dps in the Image but will cost memory). The way the OS handles the Assets is the following:
Lets say you have:
res-
-drawable
-icon.png
-drawable-ldpi
-icon.png
-drawable-mdpi
-icon.png
If you are running an app in a HIGH Density device the OS first will try to find your asset in drawable-hdpi, but since it doesn't exist it will start going down the hierarchy until it finds it, so in this case it will not find it in drawable-hdpi but will find it in drawable-mdpi and will use that one to populate, everything will be fine but will cost in memory the difference of densities in the assets.
Now the exact error you have comes to play when the OS goes down the assets folder hierarchy and goes until the end and do not find anything for example:
Lets say you have:
res-
-drawable-hdpi
-icon.png
If you run this app, in HIGH Desnity Device it will run perfect, because will find the asset in the first try and will never go down the hierarchy, same case for Extra High Density Device because if it doesnt find it in drawable-xhdpi it will find it in the next step when going down the hierarchy to drawable-hdpi and will work just fine, but for MEDIUM Density, however, first it will try to find it in drawable-mdpi since its not there, will go down and try to find it in drawable-ldpi no luck either so it will go to the "default (drawable)" which is a good practice to contain all the assets in an average size to at least make the app look blurry than crashing, since the OS will not find the Asset either BOOOM no resource found, there you have your exception, this mechanism applies for pretty much any resource in Android
2.- YES, you must create your assets in ldpi and store them either in drawable-ldpi or drawable(default - no density) in order to make it look good.
All this information has been taken out of a book and if you still have doubts, create an empty Android Project in Eclipse and notice how the SDK creates one icon_launcher.png img in each density with a specific size to handle exactly this issue. As a recommendation in my experience I've found useful to always take care of all the densities, but more important having all my assets with an average density/quality in the default folder to avoid this exact issue in case you could forget one density during development, is better a blurry asset than a crash.
Hope this Helps.
Regards!
Is there any way to say to the app to auto scale the mdpi drawables instead of crashing?
This happens automatically, unless the maker of the firmware (device manufacturer or ROM modder) screwed it up.
For support ldpi screens, must I edit the images to ldpi size?
No.
I would look up 7f02007f in the R.java associated with your production code base and make sure that it is what you think it is. Bear in mind that these numbers get regenerated on every compile. Perhaps this is a case where there simply is no drawable resource for this number, in any density, because R.java was out of sync with the actual resource packaging. To avoid this problem, do a clean build (e.g., Project > Clean inside of Eclipse) as part of making the production APK.

Categories

Resources