Android What is wrong with this 9 patch? - android

Hello,
see above for my 9 patch image. It is created using the 9 patch editor from Android tools. I have multiple issues:
The nine patch tool in preview scales the image in height as well. Why? Zhere is no black line on the left.
The nine patch tool shows bad patches. I think that means that I still can use it but it might not look good. Is there any simpler shape than this? What goes wrong when stretching?
I cannot import this 9.png file into my project without errors. So technically there must be something wrong.
Thanks, A.

Seems like both top and left lines are required by 9-patch to determine the stretchable area. You could put one pixel there. You could later fix the height of the view which uses this image to prevent it from stretching in height.

You need to add stretch information for height too. A nine patch should be stretchable both horizontal and vertically.
The bad patches are warning of artifacts may be produced when stretching.
Try deleting stretch above the green/white transition of your image.
I think the missing vertical stretch is why you get error, assuming it is has the extension 9.png.
Tips for enhancing you nine patch:
By the looks of your image you have included the right border as stretchable too, you might want to remove that.
Consider only having 3 pixels stretch above the green content, then 1px above the white content to keep the aspect ratio. There is no need to stretch the whole image. You need only 1px transparent padding from image to stretch data.

Related

9Patch image not strectching

I am using http://romannurik.github.io/AndroidAssetStudio/nine-patches.html to create a 9Patch image which is attached. . I use this is to set a drawableBottom to the TextView.But this does not stretch to the width the text view. What am i doing wrong ? This is the original image
Here are a few reasons for it to "not stretch"
Guides must only be one pixel wide, so if you want a 48×48 button, your png will actually be 50×50. Anything thicker than one pixel will remain part of your image.
guides must be solid black (#000000). Even a slight difference in color (#000001) or alpha will cause it to fail
MOST IMPORTANT: you should keep in mind that remaining area of the one-pixel outline must be completely transparent. This includes the four corners of the image – those should always be clear. This can be a bigger problem than you realize. For example, if you scale an image in Photoshop it will add anti-aliased pixels which may include almost-invisible pixels which will also cause it to fail*. If you must scale in Photoshop, use the Nearest Neighbor setting in the Resample Image pulldown menu (at the bottom of the Image Size pop-up menu) to keep sharp edges on your guides.
http://radleymarx.com/blog/simple-guide-to-9-patch/
You need to use android sdk draw9patch tool to make a 9-patch image.
you will need to define stretchable patches to image border like shown in below image border.

Why nine-patch is scaled horizontally

As an addition to my previous question, I have a image and want to place text inside the image. I've created a nine-patch image but it scaled incorrectly - I want to leave part of the image unchanged.
original file
It's how it looks in editor
this how it looks in preview (and in my sample app with width more than image width
So I want to scale only text part and leave the 'head' and 'fingers' unchanged.
The upper part (black border) tells the 9 patch to stretch the "head part" too.
Please consider using two pixels at the sides of the "no stretch zone".
Something like: . .
This way you'd have 2 horizontally stretched areas, leaving the head unstretched.
[EDIT]
At last, I saw you put the image, so here's my patched version, just in case.

9patch (nine-patch) image does not stretch /scale properly

Dear Fellow Developers,
I've ran into the problem shown in the attached picture. We have been trying to tweak the dropdown menu's 9patch image provided by a graphics designer, but could not get it to work. The black stretch markers are not being hidden, and Android does not stretch it the way we would expect.
The device is a Nexus 7. We have tried several various image sizes, but none seemed to work. I am also attaching a copy of the 9patch.
What could be wrong?!
This happens:
Here is the 9patch
If the image has been created in a normal image editor rather than the android 9 patch tool, it could be just that its not done exactly right.
The image must have a 1px transparent border other than where the black lines are. Make sure its completely transparent and is only 1 px thick
Also I don't think you can have split lines (like you have down the left and right side of the image, I think they must be one solid line on each side)

nine patch image doesn't work

I did a 9 patch image with android tool draw9patch.bat. Draw a black line only on the right side, where I want it to stretch. Saved as .9.png and set it to background of TextView:
android:background="#drawable/myninepatch"
It doesn't work, I get the image with the black line in the app and it doesn't stretch. What am I doing wrong?
I have seen at some places besides of the lines for the stretchable area there's also a very small marked area in the opposite side, but I don't know what is it for and I'm not using it.
Check this guideline . Here you can find simple UI Guideline for nine patch images .
In 9 patch images the right and bottom side lines indicate the padding, eg. the size which below the image won't shrink. The segment indicated by the top and left side line will stretch and shrink according to the desired size.

Android - ImageView scaling

Is it possible to scale ImageView only in particular part?
I have a ImageView and I would like to scale it, but only the middle part.
Left side and right would stay the same, stretching occur only in the middle.
Just like on the pic bellow:
I personally did not know that by heart but simple search showed me this result: Android - stretch image partially
It sounds to me like you want to leverage 9 patch drawables. A 9 patch is just a special version of your image that has a 1px border that defines the stretchable areas. Android directly supports this, and even has a tool to create the 9 patch images. It's pretty simple.
Documentation here: http://developer.android.com/tools/help/draw9patch.html

Categories

Resources