什么是9.png图片:

.9.PNG是安卓开发里面的一种特殊的图片,这种格式的图片通过ADT自带的编辑工具生成,使用九宫格切分的方法,使图片支持在android 环境下的自适应展示。

9.png图片如何优势:

(1)允许开发人员定义可扩展区域,当需要延伸图片以填充比图片本身更大区域时,可扩展区的内容被延展。
(2)允许开发人员定义内容显示区,用于显示文字或其他内容

效果展现,没制作前和制作后效果:

android png生成位图 .9.png 图片生成_xml

制作流程
1.给大家介绍一个网站:

阿里巴巴适量图标库链接
注册后,你就可以搜索你想要安卓图标,你输入气泡,就可以查到我将要使用的图片

2.将图片命名为message_left,并复制到mipmap中
3.右击图片,点击Create 9-patch file,初步完成9.png图片,双击message_left.9.png图片,就可以进入这个界面

android png生成位图 .9.png 图片生成_Android_02

4.制作阶段:
图片的四个边框(最外面的正方形)分别表示不同的意思
上边框黑线:图片拉伸时图片上下拉升的区域
左边框黑线:图片拉升时图片左右拉升的区域
右边框下边框黑线:文字显示的区域
鼠标键可以直接绘制黑线
按住shift+鼠标可以撤销你的操作

android png生成位图 .9.png 图片生成_android png生成位图_03


最后ctrl+s保存

5.不过这样还是不行的,我们需要将9.png图片保存到drawable文件夹下,之前使用Android模式的项目结构,直接将图片剪切到drawable文件夹下,结果报错,后来发现drawable文件夹有两个,默认会把你放到drawable-v24文件夹下,这样应用图片时就会报错,所以应该选用Project模式的项目结构,把图片剪切过来

android png生成位图 .9.png 图片生成_android_04

5.最后在布局中引用图片就可以看到他们的差别了:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.uibestpractice.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@mipmap/message_left">
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/message_left">
    </LinearLayout>


</LinearLayout>
over