In my application i'm using a background image with some text in it, it's size is 800x1280 (portrait mode)
When running the app on mobile devices , the background image looks great.
When running the app on tablet .. let's say Galaxy tab 10.1 you can see that the text in the background image is a little blurred and little pixeled..
it seems like if the image was smaller than the device resolution and got stretched.. only that image is already in the device resolution
What am i missing ?
Thanks
Your drawable folder contains folders ldpi, mdpi, hdpi, xhdpi - it's for different density per inch.
I suppose your mobile device uses mdpi or hdpi, while tablet uses xhdpi.
To get the best perfomance I recommend you to put 4 different sizes of your image to these folders. The sizes should be 0.75 x ORIGINAL_SIZE for ldpi, ORIGINAL_SIZE for mdpi, 1.5 x ORIGINAL_SIZE for hdpi, 2 x ORIGINAL_SIZE for xhdpi
update: tablets are hdpi, not xhdpi
Your device may be scaling the image somehow. Do you have your image in res/drawable? Try putting it in drawable-hdpi, drawable-mdpi and drawable-xhdpi also. This way it should pick the image fitting your resolution and refrain from scaling anything.
Note that you may want it to be scaled on other resolutions, so putting up different resolutions for different dpis is probably wise. But this is a good way to see if this is indeed the problem.
First of all, did you put your background image to specified drawable folders? :) Your image can be scaled.
If You're using linearlayout, you can check another solution, put imageview and layout into framelayout :)
Here you got examples:
android-scale-a-drawable-or-background-image
scale-background-image-in-linearlayout
:)
Related
I'm new to Android and I'd like to know why those images I put in hdpi, ldpi, mdpi, xhdpifolders are not actually responding to what I want.
In hdpi, I put images that are fit for big screens.
In ldpi, for small screens, in mdpi for normal screens and for xhdpi for tablets.
But I wonder why it's still not displaying the correct images for big screens. It looks like small images (that are fit for small screens) on the screen. I have named the images exactly the same. What is wrong with this?
I need your suggestion. Help is much appreciated. Thanks in advance.
I think that you don't have the problem in the code, nor in the images, but in the devices you're using to try the different densities. If you are assuming that larger screens means higher densities, that is not always the case. Note that hdpi, ldpi, mdpi and xhdpi refer to density, not screen size.
For example, below you can find two screenshots of the same ImageView pointing to the same #drawable/a icon but deployed in two devices with different screen density. To make the point I have placed completely different icons (both with the same name a.png) in each density folder so that the difference can be easily appreciated:
2.7" - ldpi 3.7" - hdpi
I created some backgrounds for my application. These PNG pictures are 480x800 format and testing it on my phone (with hdpi res) or on the emulator in hdpi it looks very good. But if I test it in mdpi or ldpi, the backround distorts. Since 480x800 equals to 1:1.666, mdpi format is 320x480 with 1:1.5 and ldpi is 240x320 with 1:1.333, it is natural that the background will not fit all the size perfectly. I can change the backgrounds with sharedPreferences so I cannot use the layouts for this. I do not want to put more images into the app because it's already 3 megabytes (2 megabytes for the backgrounds). How should I solve this? Should I put all the beackgrounds into to app with smaller resolutions (120x200 for hdpi, 100x150 for mdpi...) and the screen will stretch it by itself? I am afraid it would be blurred.
Thanks in advance!
Maybe you could try to use a 9-patch image instead. If that is possible for your background image of course.
http://developer.android.com/guide/developing/tools/draw9patch.html
I have drawables for each density as ldpi,mdpi,hdpi and xhdpi.
Problem:
Both 10" tablet device (1280x800) and a handset device 320x480 uses medium density. I have an 35x35 mdpi image. But this image is too small for tablet whereas it is ok for handset.
I read relevant documents. But I guess I couldn't understand sth significant. Is there anyway for tablet use xhdpi images or I wonder how to use bigger images for mdpi tablet.
You should add a second identifier large and/or xlarge to your drawable folders. Increase the size in drawable-xlarge-mdpi until you are happy with the result while the drawable-mdpi will be the same size as before.
This increases the app size, but it will fix your issue.
If you want to achieve this without increasing your app size, there is a way to let a high density screen and a large medium density screen use the same resource. You need to place the image you want to re-use in the 'drawable-nodpi' folder. This will stop the platform performing its own scaling when using it. For example, assuming you have a resource called 'my_resource', if you want the tablet-size screen to use your xhdpi resource, then move it out of drawable-xhdpi and rename it like this:
/drawable-nodpi/my_resource_xhdpi.png
Then in both the drawable-xhdpi and drawable-xlarge folders, create a file called my_resource.xml which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/my_resource_xhdpi">
</bitmap>
Now when you use #drawable/my_resource, the xhdpi version will be used by xhdpi screens and xlarge screens, and you only have to maintain one version of the image. I use this technique quite a lot and it works really well. Hope that helps!
These are defined as common practice:
Devices:
drawable-ldpi/xyz.png low resolution devices 320x240 (now a days no phone comes with this resolution)
drawable-mdpi/xyz.png medium resolution devices 480x320
drawable-hdpi/xyz.png high resolution devices 800x480
drawable-xhdpi/xyz.png Extra high resolution devices 1280*720
drawable-xxhdpi/xyz.png Extra Extra high resolution devices 1920x1080
Tablets:
drawable-large-mdpi/xyz.png 7” Tablet (600x1024 mdpi)
drawable-xlarge-mdpi/xyz.png 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
I include some resources in drawable-xlarge, and drawable-large folders, in addition to the drawable-hdpi folders. This works for me.
Another alternative, is to scale an image in code directly, which I do with the following code:
Drawable scaledIcon = new BitmapDrawable(Bitmap.createScaledBitmap(myImage, pxInt, pxInt, true));
myImageView.setBackgroundDrawable(scaledIcon);
It is not a good idea to scale a lot of images in your code (using this method), as I think it is resource intensive to modify the images on the fly like this. I do use this in some cases, where the image I am using may not be a standard size (and I want it to fit right always).
I use .png as a background for a custom button that I declare in XML like this
android:background="#drawable/samplepng"
But I can't get the resolution right for tablet screens :
For example, my ressource is a 200x200 pixels .png (initially designed for iOS and retina)
I place a 100x100 px version in the drawable-mdpi folder and a 200x200 px version in the drawable-xhdpi folder.
I also need to have a layout for a typical 320x480 screen in the layout folder and another layout for 10" tablets in the layout-xlarge folder.
The size of the button is 100x100 dp in the normal layout and 200x200 dp for xlarge layout, so that it looks right.
With the Android emulator, a 10" tablet uses mdpi ressources and xlarge layout.
As a result, the button background is drawn with a scaled version of the 100x100 image which looks very blurry, as opposed to the crisp 200x200 original image.
If I don't use a mdpi ressource, it looks blurry just as well.
Am I doing something wrong ? is it only an emulator problem and it looks nice on a real device ?
Please help, I read 10 times google's doc but can't find an answer.
If you don't launch the emulator with 'Scale display to real size' checked, then it will always use mdpi drawables.
See here for more.
Your issue might be in the android version your targeting. Try switching the emulator to android 3.0 and 3.1.
I need explanations.
I develop an application running for Honeycomb on a tablet 10.1.
I set an image 796x1228 pixel in drawable-xhdpi folder. When this image is called directly it displayed on 1/4 of screen size. If I set this image in a layout taking all screen width and height, it scales and result is not clean.
I search a long time before testing to put this same image in drawable-mdpi folder and get a good display.
The Android documentation says that for screen xhdpi we have to put our images in a folder xhdpi, but results is really bad.
Where is my trouble ? Thanks for your explanation, information...
A 10.1" Honeycomb tablet is not xhdpi. It's an xlarge display, which is completely different. The XOOM for instance has an xlarge, mdpi display.
Are you sure your device's screen is xhdpi? Usually, devices with big screens are something like xlarge, mdpi or hdpi.
If you want just to show an image on a view you can put it into drawable-nodpi, load it and apply to your view (or let the app do it automatically).