1. 9-patch介绍

9-patch绘画的是一个可以伸缩的位图图像,Android会自动调整大小来容纳显示的内容。一个例子就是NinePatch为背景,使用标准的Android按钮,按钮必须伸缩来容纳长度变化的字符。

9-patch是一个标准的PNG图像,它包括额外的1个像素的边界,你必须保存它后缀为.9.png,并且保存到工程的res/drawable目录 中。如果你是从APK解压后得到的*.9.png文件,注意它是已将周围的空白像素去掉的,在使用时必须再加上,不然eclipse会报错。

2. 使用9-patch流程说明

1. (1)From a terminal, launch thedraw9patchapplication from your SDK/toolsdirectory.

2. (2)Drag your PNG image into the Draw 9-patch window (orFile>Open 9-patch...to locate the file). Your workspace will now open.The left pane is your drawing area, in which 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.

3. (3)Click within the 1-pixel perimeter to draw the lines that define the stretchable patches and (optional) content area. Right-click (or hold Shift and click, on Mac) to erase previously drawn lines.

4. (4)When done, selectFile>Save 9-patch...

Your image will be saved with the.9.pngfile name.

Note:A normal PNG file (*.png) will be loaded with an empty one-pixel border added around the image, in which you can draw the stretchable patches and content area. A previously saved 9-patch file (*.9.png) will be loaded as-is, with no drawing area added, because it already exists.

Optional controls include:

· (1)Zoom: Adjust the zoom level of the graphic in the drawing area.

· (2)Patch scale: Adjust the scale of the images in the preview area.

· (3)Show lock: Visualize the non-drawable area of the graphic on mouse-over.

· (4)Show patches: Preview the stretchable patches in the drawing area (pink is a stretchable patch).

· (5)Show content: Highlight the content area in the preview images (purple is the area in which content is allowed).

· (6)Show bad patches: Adds a red border around patch areas that may produce artifacts in the graphic when stretched. Visual coherence of your stretched image will be maintained if you eliminate all bad patches.

3. 使用9-patch问题及解决方法

1. draw9patch.bat不能运行的一个解决方案,下载jar包,地址是:
http://netmite.com/android/mydroid/1.6/prebuilt/common/swing-worker/swing-worker-1.1.jar
下好的jar包放到:$ANDROID_SDK/tools/lib 文件里,再运行就可以。

2.Android 项目中使用Nine Patch资源,时候可能出现比如ERROR: 9-patch image android123.9.png malformed.或 No marked region found along edge.以及 Found along top edge.的错误主要是因为该图片没有四周的定位像素

再分享一个写得相当赞的关于9-patch的博文 :

http://blog.csdn.net/xiaominghimi/archive/2010/12/30/6107837.aspx


更多相关文章

  1. Android仿微信下拉列表实现(附源码)
  2. 第2步:第一个“Hello,world!”之Android(安卓)App(从零开始学Andro
  3. Android单选和多选按钮的使用
  4. 旋转中 android 的视图按钮
  5. Android(安卓)Framework 之HelloWorld(一)
  6. Sharp 在中國推出三款 Aquos Androd 手機
  7. Android点击Button切换多个图片显示
  8. 玩转Android之如何处理返回按钮
  9. eclipse里配置Android(安卓)ndk环境,用eclipse编译.so文件

随机推荐

  1. Android(安卓)执行shell脚本
  2. Android(安卓)Studio – 使用百度地图SDK
  3. Android(安卓)应用开发稳定性测试之 Stri
  4. Android中textview显示不全的问题
  5. android面试题总结加强再加强版(三)
  6. Firefox OS 学习——manifest.webapp结构
  7. Android控件复习之TextView与EditText
  8. Android(安卓)Support Library-FloatingA
  9. Android下使用正则表达式
  10. android 运行时生成dex文件,并装载调用