![Android Nine Patch Android Nine Patch](https://www.tutorialspoint.com/android/images/them2.jpg)
![Nine Patch Image Android Download Nine Patch Image Android Download](https://cdn6.aptoide.com/imgs/2/1/1/2113457c2288aa878b46b090d4728a65_screen_1024x640.jpg)
Today I discovered nine patch images. The official documentation (linked to in the other answers) is ok I suppose, but it really lacks in examples.
Has some great examples at the end that answer the second part of your question, explaining how the scaling works - not just for buttons - but also frames, and it has a complete example project that you can download and play with. The most important advantage over PNG is that nine patch images can specify non-contiguous areas to scale. To answer the first part of your question, the SDK (and now Android Studio) ships with 'Draw 9-patch' ('draw9patch' in the SDK tools folder) which is a simple editor. Which is also open source.
It has a simple but clever default image. Most of the examples talk about creating a 9-patch image, but implementation details are usually left at a high level. - with the that provides a working project download file, saved the day. Here are the main implementation details that worked for me (once you have a 9-patch image ready to go): • Reference the drawable with the name but don't include.9.png (auto-complete in eclipse will take care of this) • Make sure you only have 1 image under the main /drawable folder (not a version for each dpi folder) • The image must be specified using:background, not:src (this got me stuck for a while) android:background='@drawable/splash_logo' • Make sure the image and layout that contains it are using: android:layout_width='fill_parent' android:layout_height='fill_parent'. How can I create a 9-patch image? Is there any tool?
Can I create it from AndroidSDK or code? When you search a major search engine for android 9-patch tool, the very first hit is for. Main Advantages of 9-patch over regular png? (is it stretchable dynamically/ automatically according to screen?) The Android developer documentation contains other pages that.
This documentation includes passages like: A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View in which you have placed it as the background. An example use of a NinePatch is the backgrounds used by standard Android buttons — buttons must stretch to accommodate strings of various lengths. This is good tool: 9 Patch images are stretchable, repeatable images reduced to their smallest size. The simplest example would be if you were to take a rounded div and slice it up into 9 squares like you would a tic-tac-toe board. The four corners wouldn't change sizes at all but would be static while the other 5 pieces would be stretched or repeated to allow the whole image to scale appropriately. With that explanation and the advent of CSS3 you might think that there is no reason to use 9 patch images but the name '9 patch' is a misnomer.
The images can be sliced up into even smaller pieces. 9 Patch images contain an index of which piece is what by adding a 1px border to the image. The colors in the border determine if a piece is static (doesn't scale), it stretches, or it repeats. Google Slideshow: See also the Android developer info about 9-patch images.