NinePatchDrawable

关于.9图片突然就有几个问题

  1. 去反编译看到别人的.9图,宽高是50*100,
  2. 那如果搞成5*10不是图片会更小么?
  3. 它是怎么拉伸的?
  4. 拉伸的时候保持原有图片的宽高比么?

保持不保持原有图片宽高比跟你画的线有关.通常不会保持. 拉伸规则

a NinePatchDrawable graphic is a strechable bitmap image,which Android will automatically rezise to accommodate the contents of the View in which you have placed it as the background.

A NinePatch drawable is a standard PNG image that includes an 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 include).If the padding lines are no included,And uses the left and top lines to difine this drawable area.

image

1<Button id="@+id/tiny" 2 android:layout_width="wrap_content" 3 android:layout_height="wrap_content" 4 android:layout_alignParentTop="true" 5 android:layout_centerInParent="true" 6 android:text="Tiny" 7 android:textSize="8sp" 8 android:background="@drawable/my_button_background"/> 9 10<Button id="@+id/big" 11 android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 android:layout_alignParentBottom="true" 14 android:layout_centerInParent="true" 15 android:text="Biiiiiiig text!" 16 android:textSize="30sp" 17 android:background="@drawable/my_button_background"/>

image

点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

svg绘制六种基本形状

svg简介svg意为可缩放矢量图形(ScalableVectorGraphics),最大的特点就是伸缩不会失真。svg是用xml进行描述的,在前端方面现在应用越来越广泛,各大浏览器支持越来越好了。这边尝试记录一下用svg画各种形状。svg标签要使用svg,需要先引入svg标签:html其中:width表示图片的宽。height表示图片的高。画长

SVG动画制作工具 , 从此抛弃臃肿的gif

VG简介只要是程序员的你,你不得不知道svg图片,它可以无限任意放大拉伸都不会损失画质,就像系统字体一样可以无限矢量放大,svg更高级是可以用来制作矢量动画,现在各大浏览器和系统基本对svg已经支持很好了SVG与Gif的比较SVG图片:矢量放大,动画也是矢量,体积极小,相当于一个.txt文本的体积,几b到几kb

SVG动画制作工具 , 从此抛弃臃肿的gif

VG简介只要是程序员的你,你不得不知道svg图片,它可以无限任意放大拉伸都不会损失画质,就像系统字体一样可以无限矢量放大,svg更高级是可以用来制作矢量动画,现在各大浏览器和系统基本对svg已经支持很好了SVG与Gif的比较SVG图片:矢量放大,动画也是矢量,体积极小,相当于一个.txt文本的体积,几b到几kb

10个实用的jquery小技巧

帮助提高你jQuery应用的简单小技巧。1.回到顶部按钮2.图片预加载3.判断图片是否加载完4.自动修补破损图像5.Hover切换class类6.禁用输入7.停止正在加载的链接8.togglefade/slide9.简单的手风琴10.使两个DIV同等高度11.在浏览器标签/新窗口打开外部链

Opencv笔记(二十)——直方图(二)

直方图均衡化原理:  想象一下如果一副图像中的大多是像素点的像素值都集中在一个像素值范围之内会怎样呢?例如,如果一幅图片整体很亮,那所有的像素值应该都会很高。但是一副高质量的图像的像素值分布应该很广泛。所以你应该把它的直方图做一个横向拉伸(如下图),这就是直方图均衡化要做的事情。通常情况下这种操作会改善图像的对比度。直方图均衡化后面潜在的数