9patch是随文字大小可以缩放的图片。 定义了拉伸区域,则除拉伸区域可变外,其他区域保持原来的形状大小不变。

9patch 九宫格 9分图 它的四个角不作任何伸展,四个边分别只作水平和垂直伸展,中间部分则是水平跟垂直同时伸展,这就是著名的9-patch图,很多作背景的时候,一个很小像素数的图就可以无限的伸展为某控件背景。

一个九宫图是可伸缩的位图,在Android中将会根据视图所处位置来自适应调整成匹配视图长宽的图形。一个非常典型的例子就是Android按钮

-按钮必须根据文本描述自适应长度。一个标准的九宫图是包含额外1像素宽边框的png图片。它必须被保存以.9.png为后缀的图片文件中,并保存在工程

的res/drawable目录里。

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. 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.

这个边框是用来定义图片的可伸缩和静态区域。你可以在左部和上部使用1宽度的黑线来定义可伸缩的区域(其它边框必须是完全透明或者白色)。你可以有尽可能多的可伸缩区域:它们的相对长宽将保持相同,因此最大的片段将总是最大的。

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.

以下为可选的:你同样可以定义padding

lines在边框右部和底部画1像素宽的线。如果一个视图指定了九宫图为它的背景并设置了文本,它将伸缩它自己以便所有文本将会处于由右部和底部指定的区

域中。如果padding lines没有指定,Android使用左部和顶部来定义绘制区域。

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.

sdk\tools\draw9patch.bat工具提供了一个简单易行的方式使用可视化编辑工具来创建九宫图.当你定义的区域有导致像素重复的情况,它甚至会发出警告哦。

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.

android 九宫格绘制,Android draw9patch.bat 九宫格绘制工具使用相关推荐

  1. Android开发人员必备的10 个开发工具

    工欲善其事,必先利其器,Android SDK 本身包含很多帮助开发人员设计.开发.测试和发布 Android 应用的工具,在本文中,我们将讨论 10 个最常用的工具. 1.Eclipse ADT E ...

  2. android .9图片有黑线,用draw9patch.bat绘制的气泡图片用在Android程序中有黑线,怎么解决?...

    详情请访问我的CSDN博客: 安卓开发,对话消息的气泡框处理. 如下图所示: 问题描述: 1.边缘有黑线. 2.气泡虽然能够根据内容长短自由伸缩,但是并不能让内容显示在气泡内部. 问题解决后的截图: ...

  3. android 九宫格虚线,形状Drawable和九宫格

    形状Drawable 当你想动态画2维图形,ShapeDrawable对象是可能是你合适的选择.使用ShapeDrawable,你可以随意画出原始的形状并且应用到任何风格. ShapeDrawable ...

  4. Android 应用开发(12)---可绘制对象资源

    可绘制对象资源 可绘制对象资源是一般概念,是指可在屏幕上绘制的图形,以及可以使用 getDrawable(int) 等 API 检索或者应用到具有 android:drawable 和 android ...

  5. Android 仿小米锁屏实现九宫格解锁

    最近公司要求做个九宫格解锁,本人用的是小米手机,看着他那个设置锁屏九宫格很好看,就做了该组件,不使用图片资源,纯代码实现. 尊重每个辛苦的博主,在http://blog.csdn.net/mu399/ ...

  6. Android中.9图片的说明和绘制

    .9图片的理论 .9图片也是图片的一种,后缀.9.xxx,比如photo.9.png,图片的作用是用在不同布局的时候自动拉伸,以确保图片指定区域不失真,也就是不变形图形区域拉伸背景区域,从而让图片适应 ...

  7. SurfaceView简单理解,Android混淆,Android openGl开发详解简单图形的绘制,

    SurfaceView允许你在非ui线程中去绘制. SurfaceView的帧率可以操作60FPS 在要求实时性比较高的游戏开发中,显然,view的ondraw是满足不了你的,这时候只能是用Surfa ...

  8. 【Android 性能优化】布局渲染优化 ( 过渡绘制 | 背景设置产生的过度绘制 | Android 系统的渲染优化 | 自定义布局渲染优化 )

    文章目录 一. 背景设置产生的过度绘制 二. Android 系统的渲染优化 1. 透明组件数据传递 2. GPU 存储机制 3. Android 7.0 之后的优化机制 三. 自定义布局渲染优化 一 ...

  9. 【Android FFMPEG 开发】FFMPEG ANativeWindow 原生绘制 ( 设置 ANativeWindow 缓冲区属性 | 获取绘制缓冲区 | 填充数据到缓冲区 | 启动绘制 )

    文章目录 I . FFMPEG ANativeWindow 原生绘制 前置操作 II . FFMPEG 原生绘制流程 III . 设置 ANativeWindow 绘制窗口属性 ANativeWind ...

最新文章

  1. Windows设置共享文件夹并允许写入--windows shared folder write access
  2. 为CentOS 7安装VMware-tools
  3. master-slave(主/从)模式
  4. 使用java底层实现邮件的发送(含测试,源码)
  5. 机器学习第2天:简单线性回归模型
  6. JAVA_WEB--jsp概述
  7. Linux 之目录 -鸟哥的Linux私房菜
  8. php 地图 显示 客户位置_网站SEO优化_PHP程序网站怎么做优化 _SEO优化|SEO推广|SEO服务|上海SEO...
  9. 为什么 mysql 里的 ibdata1 文件不断的增长?
  10. Matlab计算空间权重矩阵(地理距离和经济地理距离)
  11. STM32----矩阵按键
  12. COMSOL空气反应 模型框架
  13. 电力系统中的Kron简化(Kron Reduction)
  14. 打开SharePoint时遇到“Server error: http://go.microsoft.com/fwlink?LinkID=96177”
  15. Unity-黑暗之魂复刻-跳跃功能
  16. 怎么把m2ts改成mp4
  17. 以集成和管理为主要手段的企业报表中心架构设计
  18. 这 5 本数据分析书籍,都是经典中的经典
  19. 来看看你的时间都去哪儿了
  20. 51单片机4G模块通信(EC03-DNC4G)

热门文章

  1. python mysql 驱动安装
  2. Crypto API
  3. 基于 Android NDK 的学习之旅-----资源释放
  4. 抽象类注意事项(面试常常涉及)
  5. (Alex note) Create a oracle database
  6. 精通Zookeeper系列开篇:进大厂不得不学的分布式协同利器!
  7. 太爽了!iPhone 11 包邮送大家!
  8. 《让系统发生重大宕机事故的15个方法》
  9. 2019年我只想明白了这5点
  10. 干掉服务状态!从 Session 到 Token,复杂度降低100倍!