BitmapDrawable:
这几乎是最简单的Drawable了,他表示的就是一张图片。在实际开发中,我们可以直接引用原始的图片即可,但是也可以通过xml的方式来描述他,通过cml来描述的BitmapDrawable可以设置更多的效果:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@[package:]drawable/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:mipMap=["true"|"false"]
android:titleMode=["disable"|"clamp"|"repeat"|"mirror"]
下面是它的各个属性的含义:
android:src
这个很简单,就是图片的资源id
android:antialias
是否开启图片的抗锯齿功能。开启后会让图片变得平滑,同时会在一定程度上降低图片的清晰度,但是这个降低的幅度较低以至于可以忽略,因此抗锯齿选项应该开启。
android:dither
是否开启抖动效果。当图片的像素配置和手机屏幕配置不一致时开启这个选项可以让高质量的图片在低质量的屏幕上还能保持良好的显示效果
android:filter
是否开启过滤效果。当图片尺寸被拉伸或者压缩时,开启过滤效果可以保持较好的显示效果。
android:gravity
当图片小于容器的尺寸时,设置此项可以对图片进行定位。这个属性选项比较多,不同的选项可以通过“|”来组合使用
android:mipMap
一种图像处理技术,不常用
android:titleMode
平铺模式。这个选项有如下几个值:["disable"]["clamp"]["repeat"]["mirror"]disable表示关闭平铺模式,此值为默认值。其它三个都表示开启平铺模式,但效果有差别,具体在使用中感受。
ShapeDrawable
ShapDrawable是一种很常见的Drawable,可以理解为通过颜色来构造的图形,他既可以是纯色的图形,也可以是具有渐变效果的图形。语法规则如下:
<?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:usesLevel=["true" | "false"] />
<padding
android:left="integer"
android:top="integer"
android:right="integer"
android:bottom="integer" />
<size
android:width="integer"
android:height="integer" />
<solid
android:color="color" />
<stroke
android:width="integer"
android:color="color"
android:dashWidth="integer"
android:dashGap="integer" />
</shape>
<padding>
内容与视图边界的距离