[ Web Proxy ]
URL:
Viewing: https://developer.android.com/studio/write/draw9patch [Back]  [Original]

Create resizable bitmaps (9-patch files)  |  Android Studio  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]

Create resizable bitmaps (9-patch files) Stay organized with collections Save and categorize content based on your preferences.

The Draw 9-patch tool is a WYSIWYG editor included in Android Studio. The tool lets you create bitmap images that automatically resize to accommodate the contents of the view and the size of the screen. You can scale selected parts of the image horizontally or vertically based on indicators drawn within the image.

For an introduction to NinePatch graphics and how they work, read NinePatch drawables.

[]

Figure 1. Android Studio's Draw 9-patch tool displaying a NinePatch image.

Follow these steps to create a NinePatch graphic using the Draw 9-patch tool in Android Studio. You'll need the PNG image that you'd like to create a NinePatch image from.

  1. In Android Studio, right-click the PNG image you'd like to create a NinePatch image from, then click Create 9-patch file.
  2. Enter a filename for your NinePatch image and click OK. Your image will be created with the .9.png file extension.
  3. Double-click your new NinePatch file to open it in Android Studio.

    In the workspace that opens, the left pane is your drawing area, where you can edit the lines for the stretchable patches and content area. The right pane is the preview area, where you can preview your graphic when stretched.

  4. Click within the 1-pixel perimeter to draw the lines that define the stretchable patches and (optional) the content area.

    Right-click to erase previously drawn lines (on Mac, hold Shift and click).

  5. When done, click File > Save to save your changes.

To open an existing NinePatch file in Android Studio, double-click the file.

To make sure that your NinePatch graphics scale down properly, verify that any stretchable regions are at least 2x2 pixels in size. Otherwise, those regions may disappear when scaled down. To avoid interpolation during scaling that may cause the color at the boundaries to change, provide 1 pixel of extra safe space in the graphics before and after stretchable regions.

Note: A normal PNG file (*.png) is loaded with an empty 1-pixel border added around the image. You can draw the stretchable patches and content area within the border. A previously saved NinePatch file (*.9.png) is loaded as-is, with no drawing area added because it already exists.

[]

Figure 2. A NinePatch image in Android Studio showing content, patches, and bad patches.

Optional controls include:

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2023-04-12 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-04-12 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page