Drawable的分类
1、bitmapDrawable
表示一张图片
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@[package:]drawable/drawable_resource"
android:antialias=["true" | "false"]
android:dither=["true" | "false"]
android:filter=["true" | "false"]
android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
"fill_vertical" | "center_horizontal" | "fill_horizontal" |
"center" | "fill" | "clip_vertical" | "clip_horizontal"]
android:tileMode=["disabled" | "clamp" | "repeat" | "mirror"] />
1.1 属性介绍
- src :引用一个drawableresource.
- antialias :是否开启抗锯齿**。
- dither :如果位图与屏幕的像素配置不同时,是否允许抖动.(例如:一个位图的像素设置是 ARGB 8888,但屏幕的设置是RGB 565)
- filter :是否允许对位图进行滤波。对位图进行收缩或者延展使用滤波可以获得平滑的外观效果
- gravity:定义位图的重力(gravity),如果位图小于其容器,使用重力指明在何处绘制,多个之间用 | 分隔
- tileMode :定义tile模式。当tile模式被启用,位图是重复的,并且gravity属性将被忽略。
1.2 特殊:NinePatch介绍
NinePatch 是可伸缩的位图图像,可以用作视图的背景。其实质上就是在原图片(.png)上添加了1px的边框,允许按照我们的需求,把对应的区域设置为黑色线,它在使用的过程中就可以根据我们的实际需求自动调整图形大小以适应视图内容。NinePatch图像保存的后缀名为.9.png
2、ShapeDrawable
通过颜色来构造的图形,可以是纯色,也可以是渐变效果的图片
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] >
<corners
android:radius="integer"
android:topLeftRadius="integer"
android:topRightRadius="integer"
android:bottomLeftRadius="integer"
android:bottomRightRadius="integer" />
<gradient
android:angle="integer"
android:centerX="integer"
android:centerY="integer"
android:centerColor="integer"
android:endColor="color"
android:gradientRadius="integer"
android:startColor="color"
android:type=["linear" | "radial" | "sweep"]
android:useLevel=["true" | "false"] />
<padding
android:left="integer"
android:top="integer"
android:right="integer"
android:bottom="integer" />
<size
android: