How do I set an image as background without blurring? - android

I am using Android Studio. I am trying to set a screenshot from my device, as a background image for my activity -
android:background="#drawable/active"
I have my image inside the directory- res> drawable-ldpi> active.jpeg , Which Is the lowest density folder available I am aware of. The problem is, The background looks PERFECTLY crisp and sharp in the screenshot, but when I set it as my activity's background, it blurs.
How do I fix this? I have tried moving the image to the highest density folder drawable-XXXhdpi, but it becomes worse. I have even tried the drawable folder.

All depends on your phone density. You should make few version of your image for each pixel density (but remember that even mdpi is growing older). If you properly resize image for each density your phone should take needed size of background.

Related

Android development - Drawable images resolution, how to export?

So, I am just a beginner and I already went trough android documentations about supporting different screen sizes and I understand most of it.
For my app, I created different layouts for each screen sizes and on the emulator it looks good.
Just one question.
How should I export images to my drawable hdpi.lpdi,...mdpi...folders?
Because, What I did was, I used art text2, and created a project with 700x700. Well. I set it to transperant, so it's not excatly 700x700px. cause the image does not fill the entire space.
So, before I hit export, should I change the PX Resolution for example for 450x450 or something for mdpi? But, I didn't do that, and I amnot sure if I should have done that. then i hit export and it asks me where i want it to save the image. It also gives the me option to the change the DPI Resolution in DPI, i changed to 160 and saved that in my drawable/mdpi folder. But I did not change PIXEL resoultion.
So, was it correnct? or should I have changed the pixel resoultion before, I export the actual image?
In Eclipse, However, I change the width and height of the image in dp not px. so it doesn't take the entire screen space.
I checked my app on different screen sizes in Eclipse and it looks awesome. But, in the emulator, it looks cool. HOWEVER, if open my hdpi emulator the image does not look very sharp or clear. What's the problem?
The image itself looks clear and sharp if open it with my image viewer on my computer even, the image viewer window is almost taking the entire screen of my laptop (14,1280*800).
I will suggeset you to use 9patch image. you can create 9patch image using android tool called draw9patch Located in sdk/tools.What you have to, create a high resolution image and then give to draw9patch tool it create image with extension .9.png and use that image
See the link for detail
http://developer.android.com/tools/help/draw9patch.html
Okay if i understood right, then you need to have 4 res for each image, and the aspect ratio will be "1:1.5:2:3" and some times "1:1.5:2:3:4" so you have to get all the images that you need in 3 or 4 sizes and let the android os properties do its magic by choosing the right picture based on the screen size.

Android, my app looks good on vertical screens, but size is all distorted on tablets (wide screen)

When my android app gets drawn on a tablet or a emulator that has a wide screen (wasvga,wxcage800 and my tablet) it draws the graphic images from the drawblw-ldpi folder (low res) instead of the drawl-hdpi folder. I'm curtly using a bitmap button. They are all very small (since the smallest image is being drawn) on the tables, but the correct image gets drawn on all the vertical screens.
Why is this????
Is there a way to fix it????
The default folder is the mdpi folder. If another folder doesn't exist, or doesn't have your image, android gets it from drawable-mdpi. Put your images there, and let us know if it works.

Setting correct resolution for Background image

I want to set a background image into my app. I tried to set my background image in my xml file with android:background(im using a relative layout) but it seems the image was scaled and doesn't appear to be correct or in its original form.
Let's take an example if I want to display it on a 480x800 screen and only on portrait mode. Should I also produce a background image with a resolution of 480x800?
Thanks
Yes you should. Keep in mind that there are three different directories to put your drawables in (ldpi, mdpi and hdpi drawables directories) put your background images in the appropriate directory according to pixel density and the app will chose the appropriate one to use according to the device it is run on.

Android mdpi drawables for use on both Droid phone and Xoom?

I have an app developed for a Droid (phone). In the app, I use:
Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.bg);
To set the background bitmap in the application. The bitmap is sized 480x800
which is the WVGA screen size of the Droid (without status or title bar).
Two questions:
When I rotate the phone, the Droid goes into landscape mode and the background no longer fits correctly. How do I tell the App it needs to use landscape mode when I'm not using a layout?
Second, when I run this app on the Xoom, it picks the mdpi drawable which is nowhere near the size of the Xoom screen. How do I define a second mdpi drawable that has a 1280x800 size? I think if I were using layouts, I would create a layout-xlarge directory and place a 1280x800 background in the imageview of that layout, correct?
Thanks!
Update *:
Thanks for the great answers! I upvoted everyone.
I updated the code to use drawable-xlarge-port/drawable-xlarge-land for the Xoom and drawable-port-mdpi/drawable-land-mdpi for the Droid.
I'm not using layouts as I needed to draw directly onto the activity canvas and not sure how to use setContentView() from within the class where I extend View and hook into onDraw() in order to do the animation (would need to be a separate posting).
If I can figure out how to rotate the image myself I could indeed do away with the drawable-*-land and *-port directories.
You can target drawables, not just layouts. You want drawable-hdpi-large-long-land for the first situation (assuming you're letting the system handle rotation events and recreate your activity), and drawable-mdpi-xlarge for the second.
Of course it's futile to try to ship with a separate image for every conceivable phone resolution; partially because there's a lot you'd need, and partially because some targets aren't differentiable (the 854x480 and 800x480 phones out there are all hdpi-large-long, for example, despite the 54px difference). Try to use a scaleable image, a stretchable 9patch, or an image you can just fix at the top-right corner (you can define stretch behaviors using an XML-defined bitmapdrawable).
When I rotate the phone, the Droid
goes into landscape mode and the
background no longer fits correctly.
How do I tell the App it needs to use
landscape mode when I'm not using a
layout?
If you alreay detect the rotation, then the Device class is the way to go.
Second, when I run this app on the
Xoom, it picks the mdpi drawable which
is nowhere near the size of the Xoom
screen. How do I define a second mdpi
drawable that has a 1200x800 size?
You can use various image folders dependending on the resolution of the device: ldpi, mdpi, hdpi or xhdpi. You should take a look at the following page for proper support of various resolutions and screen sizes.
That's just about right. You can mix in portrait, landscape, and other modifiers, too. Don't forget to use them with your drawables as well as your layouts (and any other resource directory, for that matter). If it's the same layout and different drawables, then you only need to apply it to the drawable, for instance.
You'll want to look at the documentation for resource directories and make use of the size and orientation directory modifiers.
For example:
drawable-land-mdpi
drawable-xlarge-land
layout-port-mdpi
and such
For more information, see:
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
http://developer.android.com/guide/practices/screens_support.html#qualifiers

Android large-sized emulator produces regular size application in center of screen

I always used the standard emulator when testing and thought it was about time to see what it looked like in a higher res/density setting. I ran my application using WVGA854 which has a density of 240 (rather than the 160 I usually used). The result is my application sitting as its old size in the center of the screen. I don't specifically hardcode the application size anywhere that would produce this (except for background images, but there are other things like x,y positions that are still limited by the old size). What gives? I move over the high res images into the correct folders but it still appears to be forcing my app to a smaller size? The background below is set to 854 width in the HDPI (and MDPI folder) but it is still cutting it off? Using a surfaceView to draw the bitmaps.
Add the <supports-screens> element to your manifest, saying that you support large screens.

Categories

Resources