I have a background image defined in res/drawable-hdpi, and it looks fine on all phones, it's a standard 480x800 image that scales well for other screens with similar aspect ratio. The image of course fits pixel-perfect on 480x800 phone.
Now I've bought a 7" tablet that also has 480x800 screen, but is a large screen.
Although the image itself IS 480x800 and tablet has the same resolution, the image looks like it was downscaled to smaller size and then upscaled again.
I have a temporary solution that works - to place the same image into res/drawable-large folder, which works, but I have the same image twice in my project which I think is unnecessary.
I suspect it has to do with the image being in res/drawable-hdpi, and because the tablet is MDPI, it did some scaling down and scaling up, but I'd like to avoid this and do it properly, so I can use the same drawable in one folder, and it will work correctly on phones and tablets.
you can put that particular image in "drawable" folder.
Related
I have an application that uses ImageViews to show some pictures. The image sizes are 320x480px.
I use some animation to move these pictures to the center of the screen and when the phone has the resolution of 320x480, it works great.
However, when I tried it on emulator with the resolution of 240*320, there were some problems:
The ImageView is still 320x480 so it looks way too big
The animation that uses the screen resolution can't move the pictures to the center, it is at least 20-30 px off
I learned the when dealing with pictures, Android dynamically changes resolution of them to make the images fit in. How could I set that these images should be resized according to screen resolution?
It's hard to say what's wrong without seeing any code. Android resizes images from res/drawable according your screen resolution (ldpi, mdpi, hdpi, etc.). If you place pictures in res/drawable-nodpi, they will not be scaled. You could also use the density dependent folders res/drawable-ldpi, res/drawable-mdpi, res/drawable-hdpi etc. You should definitely read the docs here.
I believe that android:adjustViewBounds="true" and android:scaleType="fitCenter" is what I needed. The ImageViews are scaled down to 240x320 and the animation works well.
Interesting that the upscaling is not proper. When I used in the emulator at 480x800, my ImageView is scaled up to 480x720 so I get black edges. Any idea for that?
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
:)
In the beginning I created my application to work on all resolutions, tested on my phone with small screen and large screen tablet.
As I had created the images for drawable-hdpi, MDPI, ldpi, each image with its resolution, he was adjusting.
However now I'm testing again on the tablet and the resolution cell is small, is only correct for the phone, she stopped to adjust the tablet increased.
Do not know if it was some setting I made in layout,
I'm using relative layout, fill_parent and wrap_content.
And in some cases put margin, and alignment, below ...
Anyone know tell me how to adjust automatically, or imagine what might be wrong?
I think you missed something about density.
Image auto scaled by os with density, as an example in lower density Image will be scaled smaller.
As lulumeya said this is for sure problem of density of tablet you are using to test
For tablet instead of putting images in "drawable-hdpi" or "drawable-xhdpi" for large screens,
put them into folder named "drawable-xlarge" in /res folder.
This folder will be used for
large screen devices such as tablets.
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).