how does a 9patch png work in android apps
Asked Answered
L

3

9

In a 9patch png, there are black edges in its four sides, but there is usually difference between the left to right, and the up to down side. Why? How does this difference impact?

Letterhead answered 23/12, 2010 at 10:4 Comment(0)
C
20

One of simplest ans is this pic

draw the black line according to your requirement using nine patch tools.

Celenacelene answered 11/5, 2012 at 10:50 Comment(1)
Isn't the example a bad patch (gradient in scalable are on the sides) ?Romeo
L
7

The left and top are for scaling, and the right and bottom are for content. So the black lines on left and top will scale to fit, and the content for a button will be "inside" the black lines on the right and bottom.

Largely answered 23/12, 2010 at 10:10 Comment(1)
Your answer is still available in 10 years later. Thanks!Playpen
L
3

Here http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch you can find a very good explanation, with images to show you that the left and top part of the black border indicate a stretchable section, while the right and bottom lines define the drawable area, where you can put your content.

Lues answered 23/12, 2010 at 10:33 Comment(4)
@Adinia, so the 9patch differs from the scaling of a simple png bitmap by being able to apply these extra padding and scale regions within the image?Amide
@Amide Yes, with a 9patch you can define yourself the scaling regions of the picture and 'protect' from scaling some parts of it, instead of scaling all the png.Lues
@Adinia, the padding is optional; as if it is the default extra x&y points of extra space around the stretchable region? So in the environment of excessive or too little space the padding protects the image from becoming smaller? (is that correct?)Amide
@Amide The padding is optional indeed and has no impact over the image size, but over it's content size(in the example at the link, the padding define the zone that can be occupied by the text, inside the button)Lues

© 2022 - 2024 — McMap. All rights reserved.