Android Patch Utility

I would like to know why we use nine patches? I know that I need to compress or stretch the images, but if I want to resize the image, we can’t just do it in a special image editor, for example, gimp?

+6
source share
8 answers

What is a 9 patch?

9-patch images are stretched, repeated images are reduced to the smallest size; users draw a 1-pixel right and bottom solid black border to tell the system how to place content inside the image.

The 9 patch is a PNG image with an extension to the file name (filename.9.png) that allows the Android system to determine how the image can be stretched and distorted to fit the specific layout constraints.

The Android operating system reads the borders of these images to understand how to properly stretch the image and content in the image, such as text and effects.

9-patch theory 9 patch image concept

9-patch gets its name from the fact that the created overlay splits the image into nine specific areas. Each region has certain tensile properties:

Corner Regions (1, 3, 7, 9) These regions are fixed and nothing inside them will stretch.

Horizontal sides (4, 6) If necessary, the pixels in this area will stretch vertically.

Vertical sides (2, 8) If necessary, the pixels in this area will stretch horizontally.

Center (5) The pixels in this area will stretch uniformly in both horizontal and vertical directions.

here are google docs

+16
source

Nine patch images are very useful because it reduces your resource, and you can maintain the shape of the curve, which stretches into a regular .png.

  • Reduces resource: you can make a small NinePatch image and stretch it as much as possible, repeating Pixel

  • An edge angle is supported, even if the display size changes.

  • There is no need to program the add-on , you can reserve a text area in NinePatch directly.

The upper and left borders of the pixels define the stretch area. However, the lower and right regions define the CONTENT region. If you want the gasket to be removed, you need to make the bottom and right strip the width to the edge of the cover (although not completely to the corner pixels!). Basically, the right and bottom borders of pixels define your complement.

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch enter image description here

http://www.developer.com/ws/android/programming/Working-with-NinePatch-Stretchable-Graphics-in-Android-3889086.htm

enter image description here

+6
source

The advantage of using 9-patch images is that when using it as a background, for example, the image will not stretch and lose proportions in different screen sizes. the center β€œpatch” will remain as it is, and the β€œborders” will be stretched to fit the size of the screen / view.

another and big advantage is memory. The same small size memory can be reused for different screen size devices. Processed 9-patch images with design are less error prone and have a high degree of reuse. It was difficult for me to optimize the interface for different resolutions, until I knew that Android supports 9-patch.

For padding, as @hotveryspicy says you can use the padding field (where your text button will be populated) to define your paddig values, and they are defined as follows:

  • padding-top: the distance between the top edge of the pad and the top edge of your button
  • padding-bottom: the distance between the edge of the button pad and the edge of the bow of your button
  • padding-right: distance between the right edge of the pad and the right edge of your button
  • padding-left: the distance between the left edge of the pad field and the left edge of your button

We hope this helps you get a clear idea of ​​how important the 9 patch pattern is.

+5
source

Nine-patch is used to dynamically stretch and compress the image at runtime. This is the reason why it cannot be compared with static image resizing using the image editor.

Nine-patch is used for things like borders that dynamically change to fit the content, so they should stretch dynamically.

+3
source

9-patch images are not just enlarged; they are "stretched" in a certain way. The classic case is a button with rounded corners. If the button were simply scaled, the radius of the corners would also be increased. With 9-patch images, the angles can be defined so that they remain the same, and the lengths of the edges are increased.

+2
source

You worked with css. if not, then there is one property called repeat that gives you the ability to repeat a 1px image 1040 wide and even more without starch

The 9 way does the same, for a while due to the different resolution of the images, and creates a separate image for each phone, creating 9 patch images.

Hope that helps

+1
source

Nine patches is to stretch at runtime ... If you use a button with a custom background, for example, and say width-> fill_parent ... there are many different devices out there with different resolutions, how are you going to prepare images for all of them. .. you give nine patches and stretch them on the go.

+1
source

Nine patches allow you to draw only part of the image, not the entire image. It may be useful to create, for example, custom buttons, EditTexts, etc.

You can describe more here: http://developer.android.com/tools/help/draw9patch.html

+1
source

All Articles