关于.9图片突然就有几个问题
- 去反编译看到别人的.9图,宽高是50*100,
- 那如果搞成5*10不是图片会更小么?
- 它是怎么拉伸的?
- 拉伸的时候保持原有图片的宽高比么?
保持不保持原有图片宽高比跟你画的线有关.通常不会保持. 拉伸规则
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.
<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"/>