ver: 128 x 128 circle sprite with Linear, Linear filter. It looks fine on a Full HD resolution, but on lower resolution I can see alot of the pixels. + on some devices top and right pixels are missing
ver: So I made a 127x127 circle on a 128x128 dimension png. + I also manually made around the edge a 2pixel transperancy, that goes from 100% transparent to 0, so it would look smooth in game. On Full HD still looks fine, but now on smaller screens the edge looks blurry. And still top and right are missing pixels, but a little less.
1 - What is causing the missing pixels? And so randomly across devices. Somewhere missing, somewhere not, if I would make a 125x125 circle, I would get all the pixels, but what is the problem?
2 - How do you go about making for all the phones. Although 2nd version still looks better, but it seems like it is blurry around the edges.
Related
I have an idea for an application for Android. I have a decent background in Android but I have never encountered a problem like the one I am currently facing.
Background
I am creating an overlay activity on top of WhatsApp. When you launch WhatsApp a red circle shows on the overlay activity and it needs to be entered exactly above the "new chat" button in the latest version of WhatsApp (Android Lollipop).
This is easy when positioning with DP on a specific device but this circle will not be in the correct location if I test the app on my LG G3.
The obvious answer is that I would create a xxhdpi layout too, but the problem is that this circle needs to be dynamic, so if I want it to be above the search button, it needs to be there.
Question in a sentence
My question is based on margins in DP on a specific device, how can I make sure the circle appears in the exact same position on all other devices that have the same version of WhatsApp?
Example: On Note 3 (1080p, 388 PPI) margin right is 30dp, How do I use the resolution knowledge and DPI knowledge to make the circle appear in the same place on my LG G3 (1440p, 538 PPI)
What I have tried
Firstly the dumb approach at positioning it correctly on phone one with dp and running on phone two (Failed)
Second I tried positioning according the width of screen in pixels times a percent (I.E. screen_width * 0.75) so the circle will appear always at position x 75% of the screen (Failed due to screen density? 1)
Thirdly I tried the same approach as my second attempt but instead of raw pixels I used the total screen DP and used that as my relative measure (I.E. screen_width_dp * 0.75) so the circle will appear always at position x 75% in dp of the screen. (Failed 2)
Notes
In all tests I made sure that the units I am working with are correct, for example if I had screen_width_dp x 0.75 I made sure to convert the DP into PX before setting the margins.
1 - Why would this fail? using screen resolution ratios.
2 - Why did this try fail as well?
This was tested on Note 3 (1080p, 388 PPI) as base phone, and LG G3 (1440p, 538 PPI) as secondary phone that the circle should move relatively to be placed correctly on.
Thanks!
I've a 9-patch image which contains 2 horizontal stretchable areas and 2 vertical stretchable areas like this. It looks good in draw9patch and the emulator.
Unfortunately it becomes strange in real devices, I tested it with Asus Nexus 7 (Android 4.4.3) tab and Sony Xperia Tipo ST21i (Android 4.0.4) phone. This is a view set that drawable as the background.
Why does this happen and how to fix this?
I suspect this was because of scaling of the base image to adapt screen density. The image in the question is for hdpi. Widen the stretching area from 1 px to 2 px solved this problem, but it is strange that the circle is not center aligned in Asus Nexus, it is slightly to the right than it should. However it looks fine in Sony Xperia (centered).
So, I still wait for another better answer.
I'm making a game on Android in Eclipse, and when I run it through the emulator, it appears fine. The emulator I set up has the resolution at 800x480 (sideways). When I run the game on my phone, with resolution 1920x1200, it screws up the bitmaps by only drawing a fourth of them. I've made test code and two screenshots to show what I mean.
Small screen, emulator, running 2.3.3
http://i.stack.imgur.com/2WstK.png
Large screen, Galaxy S4, running 4.2.2
http://i.stack.imgur.com/8wtAD.png
It's the same code on each. The top has the dimensions correctly in the emulator (frame size of the bear, which is 64x64), but on the larger resolution it's halved the width and doubled the height for some reason.
The bear at the bottom is set to be near the bottom coordinates whatever the screen size, which is why it's different in each screenshot. The rectangles and top bear is set from the top coordinates.
I can post code but I'm just wondering if it's some type of setting that I'm unaware of because of the difference in resolution.
One more thing, I have the rectangles flipped horizontally from their original bitmap, so the fact that it appears to have taken the top right part of the bitmap to draw is not part of this, as far as I know. Again, just wondering if it's some setting that auto-scales things if the resolution is huge. I have a feeling it's something like that, OR that it's running on such a newer version of Android. Could be lots of things I guess.
Android usually scales up / scales down the image if it cannot find the right image assets for the device resolution. I believe this could be the reason for the behaviour you are observing. You can read more about providing the proper assets for different device configurations here,
http://developer.android.com/guide/practices/screens_support.html
Alternatively, if you don't want android to scale your images you can also place the image resources under drawable-nodpi folder.
Depending on the device, my 9patch is acting differently. Ideally, it looks like this:
Which is the result I get on a Nexus 4. However, on a Nexus 7 I'm instead getting this:
It's stretching properly, but there's a shadow over what should be transparent. draw9patch.bat says there are no bad patches, and stretches correctly. The two devices are different resolutions (xhdpi and hdpi), but I made sure to include the same 9patch in both folders (drawable-xhdpi and drawable-hdpi).
I used to have problems with 9patch when setting just un pixel in any of the four sides.
I see that in your 9patch you are only using one pixel to draw some of the lines that define the stretchable patches and content area. Try using more than one pixel in top, left and right sides of your 9patch.
I'm wanting to target WVGA (480x800) and FWVGA (480x854) devices with my program. My question is: for my full screen background bitmaps which resolution should I make them?
There are a few ways you can attack this issue.
Make one background per aspect ratio and calculate which to use when the app starts. Find the aspect ratio by dividing the width by the height.
Make one background with filler on the sides and bottom for cropping, when you display the image resize it's dimension which has the largest difference from that of the screen's resolution to the exact screen resolution. This will cause the bottom or sides to get cropped a bit.
You could also use a combination of these strategies to create a couple backgrounds, one each for a range of aspect ratios, and then use the cropping strategy to take up the negligible difference.
Be flexible. Android can be run on many different devices, and it would be a very bad idea to limit yourself to certain resolutions. Instead, write your code so that it scales. (Keep it mind that you might have to crop the image if necessary, or live with different aspect ratios).
Just as food for thought... there are Android devices with 480x320, 240x320, 480x800, 480x854, not the mention the upcoming Samsung tablet at a higher resolution. Limiting yourself to a certain resolution would be bad.
Here is something from the SDK you may want to read up on too: http://developer.android.com/guide/practices/screens_support.html
EDIT: Assuming that you're focusing on those two resolutions -- I would say it depends on your image. Your best bet may be to go for 480x854 and design the image in such a way that it won't look bad if you lose 27 bytes on either side. If that's impossible, make it 480x800 and add black bars on either side if run on 480x854.
you can get any bitmap and convert it into a drawable using BitmapDrawable .Then you can set bounds to the drawable to match your screen background.
I've made my background graphics 480x864, the hdpi equivalent of WQVGA and thus as large as it gets. Since I center background graphics vertically, this will display nicely on QVGA, HVGA, WQVGA and WVGA, cropping a bit in most cases. To make sure that the important elements are always seen, I limit them to an area of 480x640 in the center.
To leave nothing to chance, I provide scaled down versions of the graphics at the same aspect ratio for MDPI and LDPI. Works great so far.