`
ericbaner
  • 浏览: 173787 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

9-patch图片的制作方法

 
阅读更多

 

Nine-patch

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. A NinePatch drawable is a standard PNG image that includes an extra 1-pixel-wide border. It must be saved with the extension .9.png, and saved into the res/drawable/ directory of your project.

The border is used to define the stretchable and static areas of the image. You indicate a stretchable section by drawing one (or more) 1-pixel-wide black line(s) in the left and top part of the border (the other border pixels should be fully transparent or white). You can have as many stretchable sections as you want: their relative size stays the same, so the largest sections always remain the largest.

You can also define an optional drawable section of the image (effectively, the padding lines) by drawing a line on the right and bottom lines. If a View object sets the NinePatch as its background and then specifies the View's text, it will stretch itself so that all the text fits inside only the area designated by the right and bottom lines (if included). If the padding lines are not included, Android uses the left and top lines to define this drawable area.

To clarify the difference between the different lines, the left and top lines define which pixels of the image are allowed to be replicated in order to stretch the image. The bottom and right lines define the relative area within the image that the contents of the View are allowed to lie within.

Here is a sample NinePatch file used to define a button:

This NinePatch defines one stretchable area with the left and top lines and the drawable area with the bottom and right lines. In the top image, the dotted grey lines identify the regions of the image that will be replicated in order to stretch the image. The pink rectangle in the bottom image identifies the region in which the contents of the View are allowed. If the contents don't fit in this region, then the image will be stretched so that they do.

The Draw 9-patch tool offers an extremely handy way to create your NinePatch images, using a WYSIWYG graphics editor. It even raises warnings if the region you've defined for the stretchable area is at risk of producing drawing artifacts as a result of the pixel replication.

Example XML

Here's some sample layout XML that demonstrates how to add a NinePatch image to a couple of buttons. (The NinePatch image is saved as res/drawable/my_button_background.9.png

<Button id="@+id/tiny"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:text="Tiny"
        android:textSize="8sp"
        android:background="@drawable/my_button_background"/>

<Button id="@+id/big"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true"
        android:text="Biiiiiiig text!"
        android:textSize="30sp"
        android:background="@drawable/my_button_background"/>

Note that the width and height are set to "wrap_content" to make the button fit neatly around the text.

Below are the two buttons rendered from the XML and NinePatch image shown above. Notice how the width and height of the button varies with the text, and the background image stretches to accommodate it.

分享到:
评论

相关推荐

    点九图片素材制作工具Nine-Patch

    自动去黑边,自动识别点九过的图片的处理信息,重新进行编辑。处理完的点九信息在查看时看不到边缘黑线,但是可以在手机上被正确识别,做手机界面设计等的可以来取了

    draw 9-patch教程

    制作.9.png图片,draw9-patch教程及draw9-patch

    9点素材制作工具Nine-Patch Editor1_0_0_3

    android 中的图片制作工具 9点素材制作工具Nine-Patch Editor1_0_0_3

    聊天气泡框 Nine-Patch图片

    仿微信,聊天气泡框 便于制作Nine-Patch图片,很实用,在网上找了很久,大家可以下载使用用于练习

    android .9图片工具 .9-patch

    很久没上传资源了,今天特意把自己收集的,自己用过的资源上传。Android.9png图片制作工具,这个工具是增强版,可以同时处理多张图片,处理的图片不会有黑线。非常的好。

    安卓.9PNG制作工具及使用说明draw9patch_cn.rar

    通过工具制作出的PNG图片,在拉伸是保持原样,是个人开发爱好的基础技能。 1、加黑边:把PNG图像拖放到这个工具的窗口中(或者通过File-&gt;Open 9-patch)。左边的窗格是你的绘画区域,右边窗格是预览区域。在1个像素...

    draw9patch.zip

    中文版draw9patch,制作.9图片十分方便呢!解决 Android 开发 ERROR: 9-patch image

    draw9patch 9png制作工具

    draw9patch是一个对png图片处理的一个工具,能够生成".9.png"的图片

    9png编辑器draw9patch汉化版

    9png编辑器draw9patch汉化版,用来编辑制作9.png图片

    9patch mac版 点9工具(安装包)

    9patch mac版 点9工具(安装包)

    Android draw9patch 图片制作与使用详解

    Android draw9patch 图片制作与使用 理解一下4句话: 上边 决定左右拉升不变形 左边 决定上下拉升不变形 右边 设置内容高度区域 下边 设置内容宽度区域  下面我拿6张图片分别举例说明: 1.QQ多彩气泡 聊天对话框...

    vcxsrv-64.1.20.1.4-wsl-patch.installer.exe

    可以只在托盘有一个单一的图标(见下面的图片)即可,不需要开一个什么Shell来不断的开启其他的软件 可以制作成菜单的形式来使用,如同一个开始菜单一样 容易配置 开发很活跃,而且在SourceForge中评价很好

    xUltimate-9patch

    在自己制作.9.png图片的时候,制作之后所制作的图片上面会显示出制作的痕迹,也即是图片区域上会显示小黑点和黑线。那么为了真正的利用.9.png图片的使用效果,这些瑕疵当然是不能出现的了。因此,要想办法去掉她们这...

    draw9patch.rar

    9png图片制作工具

    9patch图片编辑小工具

    免安装,解压即用,打开后缀为.9的图片工具,可以进行编辑保存。可制作.9格式的图片。

    draw9patch-master.zip

    android studio .9 图片制作界面不友好

    9.png图片制作+去黑边软件集合

    9.png 制作软件,draw9patch 加去黑边软件xUltimate-d9pc-x86。安卓美化必备利器。

    draw9patch

    9.png 格式图片,包含制作和去黑边工具

Global site tag (gtag.js) - Google Analytics