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.
Related
my phone is galaxy s9 that is 5.8 inch and xxhdpi. And my virtual test phone is nexus 5 that is xxhdpi but the screen size is 4.95 inch. The imageview from the Galaxy S9 appears to be cut off from the Nexus 5. Layout-xxhdpi applies to the same device, with some looking right and some looking fired. How can I solve this?
I would like to recommend you use Vector drawables.
The major advantage of using a vector drawable is image scalability.
It can be scaled without loss of display quality, which means the same
file is resized for different screen densities without loss of image
quality.
Vector drawables allow you to replace multiple png/jpg/jpeg assets with a single vector graphic, defined in XML.
FYI- For responsive Textsize issue, You should use SDP
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.
I'm trying my app on a Samsung tab 2 (10.1) and it is supposed to have a resolution of 1200x800. My images take up about 75% of the screen, but even if I create them with the size of 1280*800 with 320 dpi they still look kind of blurry.
However if I create them even larger, for example 2000 in height (it's a portrait app), they look sharp. Why do they have to be that large in size? What am I missing?
I'm sure others have had this issue but I couldn't find a good solution by searching.
Thanks.
/Nick
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 want to put a toolbar in my application. The toolbar will use ImageViews as application buttons. I would like the ImageViews to be the exact same size regardless device; by "same size" I mean that, when rendered to the screen, if I measure them with a ruler, the dimensions will be the same. I would like this size to be ~10mm (the width of my index finger).
I have been completely unsuccessful in accomplishing this.
I am testing on a MDPI, large screen Acer Iconia Tab and a HDPI medium screen Samsung Galaxy Tab. If I set layout_width="50dip" and layout_height="50dip", the buttons render as ~10mm on the Samsung, and ~8mm on the Acer. If I set the buttons as layout_width="12mm" and layout_height="12mm", they render as 12mm on the Acer and ~9mm on the Galaxy (confusing that 50dip renders bigger on the Galaxy than the Acer, but 12 mm renders smaller on the Galaxy than on the Acer).
If I place a 32pix x 32pix icon in my drawable-mdpi folder (and no equivalent in the drawable-hdpi folder), and set layout_width="wrap_content" and layout_height="wrap_content"; the results are similar to if set to 50dip, the Samsung is about 10mm, the Acer about 8mm. If I add a 48pix x 48pix icon to my drawable-hdpi folder, there is no change; presumably because the Acer still uses the mdpi icon and the Samsung uses the bigger one, but scales it down by 50% because it knows its hdpi (if am confident that this surprising scaling occurs because if I move the 48pix icon to the mdpi folder, and have nothing in the hdpi folder, the icon shows very large on the Samsung).
I am confused and could really use advice. How do I make my button fingertip sized regardless of dpi and screen size?
Ok, I finally figured out what is going on:
The problem is that a image button who's width is specified as 10mm,
shows as about 7mm on my Galaxy tab, and about 9mm on my Iconia Tab.
There are 2 reasons for this rather significant difference:
The Iconia Tab reports its xdpi as ~160, when its actual xdpi
is ~150.
Honeycomb uses a new drawable for its button background, with
significantly smaller margin than the drawable in Froyo.
Issue 1 accounts for about .6mm of the difference, Issue 2 accounts
for the remainder. Issue 2 can be solved by choosing one of the two
backgrounds, packaging it with the application, and specifying it as
the background for the ImageButton. Issue 1 cannot be resolved, but the difference it creates is relatively minor once issue 2 is dealt
with.
You have two basic approaches:
Use supplied resource indentifiers - hdpi/ldpi/etc - and just rely on the OS.
Use xdpi/ydpi in DisplayMetrics class. They are supposed to return the exact physical pixels per inch and scale the image manually with a corresponding scale factor. This, of course, will slow down performance. What is more - I am not sure whether these readings will be correct.
Did you try stuff in the no-dpi resource identifier. Honestly I'm not sure what you would get out of this but it's worth a shot.