Droid 9-patch Splash is black on some devices - android

I'm using a 9-patch to place a logo on the splash screen. This works on most test devices, as well as on simulators, but on one particular device – an SM-T230 – it shows up like this:
Image of splash screen where all space under the logo is turned black (Logo is deliberately blurred)
I created the 9-patch for all DPIs (LDPI, HDPI, ...).
It does appear to be scaling it; its size (in raw pixels) is about halfway between the size of the MDPI and HDPI images.
Any thoughts?

I believe I solved this by adding an extra pixel margin around the content of the image.

Related

Android: Create an image that covers the screen for different displays

I want to add a background image to one of the screens of an Android app. (This image is a photo so 9-patch will not work).
I want scale this image for various different resolutions.
Android organises images uses DPI (i.e. ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi). However this does not seem useful in this particular situation as I want to use an image that covers the ENTIRE screen. DPI does not tell me how big the entire screen is. For example, a xxxhdpi screen may have a lower resolution than a ldpi screen.
To illustrate this issue consider the following devices:
Samsung Galaxy Tab 10: mdpi, 800px x 1280px
Moto G: xhdpi, 720px x 1280px
As you can see the first device requires a larger resolution image, despite having a lower dpi.
Therefore my question is, how do I create an image that covers the screen for different screen sizes.
You can find several answer at stackoverflow like: Android: Background Image Size (in Pixel) which Support All Devices
Another reference including tablets can be found at: Is there a list of screen resolutions for all Android based phones and tablets?
The detailed description can be found at: https://developer.android.com/guide/practices/screens_support.html
One point you need to keep in mind is how the image will cover your layout, you need to fit using center crop as scale type.
Remember to leave some space from borders at least not including important information that could be cropped from the border based on the real device size.
Another way to add backgrounds for multiple size and densities is not trying to cover the entire scree just a mix. A gradient plus some image can give you enough flexibility many times.
Another solution is using a blurred image which do not interfere with the rest of the information shown. In this case because of the nature blurred of the image, it is not required to be detailed.
Hope it helps.

How to set ImageView to apply image size to screen resolution in Android

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?

Android - drawable scaling for tablet

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.

Android: position of buttons in screens with different resolutions

My Android application consists of several UI screens that contain a background resource and buttons that are placed on top of it.
The position of the buttons on top of the background is determined in the xml file of the layout.
In screens with different resolutions the background is resized to fit the screen.
This creates a problem that the buttons are not placed in the right place on top the background.
For example:
Using an emulator I checked it on a variety of normal size screens.
The background I used is compatible to a 480x800 resolution with density 240. But when I run it on an emulator with resolution of 640X960 and density of 320 the background is resized and the buttons are not placed in the right place.
The same thing happens on an emulator with resolution of 320X480 and density of 160.
Consider not sizing the picture to the total size but setting it to a defined size. So you will have somehow a black frame around your picture but no problem with different screensizes.

What resolution should my Android splash screens be?

I'm creating a splash screen that will display while my Android application loads. I'd like to create it at the correct size so Android won't auto-scale it up or down to fit the screen. (It's a bitmap image, a photograph of an oil painting, so I can't just turn it into a nine-patch.)
But there are at least three important screen sizes I care about: 320x480, 480x854 (Droid), and 480x800 (Nexus One).
I've read the documentation on supporting multiple screen sizes, but I still don't see how I'm supposed to configure different splash screens for Droid/Nexus one (they're both "hdpi" resources as far as Android is concerned), and I don't know exactly how large my splash screen should be in any case. (How tall is the OS title bar/menu in Droid? N1?)
What size should I make these images, and how do I tell Android to use the correct size on a given screen?
You don't need to worry about the absolute screen size or status bars or anything — that's why we have nine-patch images.
What I did was have an image that looked good for each resolution — essentially a logo on a transparent background, with some text at the bottom.
Then I chopped off quite a lot of space at the top and side edges, made a nine-patch border round the image, with a single pixel near the left, right and top edges. This allows the image to expand evenly at the sides and top to fill the screen.
Edit, in response to Dan's comment below:
Yes, there is a way to determine which graphics should be used for which explicit screen sizes, but it's deprecated.
Just as there are drawable-hdpi and -ldpi resource qualifiers, it's also possible to use drawable-HHHxWWW — the larger pixel dimension coming first.
e.g. drawable-800x480 and drawable-854x480
Okay, firstly: you can find the device model via android.os.Build and use that to determine which image to show.
Secondly, I personally wouldn't bother. Layouts should be done in dip since every android screen is 320x480 dip I believe, and android maintains aspect ratio among devices very well through this in my experience. A 480x800 splash set to fill parent has been pretty reliable on both N1 and the droid as far as I have encountered.
Another solution that I implemented is to put an ImageView that fills the screen (width and height both "MATCH_PARENT") with scale type "centerCrop". This way, the image is not stretched but cropped along the edges. Try not to put important content (logos and stuff like that) close to the edges. If it is a photograph, I hope that the edges are "expendable" and can be cropped out.

Categories

Resources