<?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="integer"
android:startColor="integer"
android:type=["linear" | "radial" | "sweep" ]
android:useLevel=["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>
- android:shape
- 表示图形的形状, ring和line必须搭配
stroke
使用, 针对ring的几个属性 - android:innerRadius 圆环内半径
- android:thickness 圆环厚度
- android:innerRadiusRatio 内半径占整个Drawable宽度的比例
- android:thicknessRatio 厚度占Drawable宽度的比例
- android:useLevel 一般用false, 除非在LevelListDrawable中
- corners
- android:radius 为四个角的角度, 优先级低
- android:topLeftRadius 左上角角度
- android:topRightRadius 右上角角度
- android:bottomLeftRadius 左下角角度
- android:bottomRightRadius 右下角角度
- gradient
- 与solid互斥, 表示渐变效果
- android:angle 渐变角度, 默认为0, 必须为45的整数倍, 0表示从左到右, 90表示从上到下
- android:centerX 渐变中心点横坐标
- android:centerY 渐变中心点纵坐标
- android:startColor 渐变起始色
- android:centerColor 渐变中间色
- android:endColor 渐变结束色
- android:gradientRadius 渐变半径, 当type为radial时有效
- android:useLevel 一般为false作为StateListDrawable时为true
- android:type 渐变类别
- solid
- 纯色填充, 通过android:color指定填充色
- stroke
- android:width 描边的宽度
- android:color 描边的颜色
- android:dashWidth 组成虚线的线段的宽度
- android:dashGap 组成虚线的线段的间隔
- padding
- 表示包含shape的View的空白
- android:left
- android:top
- android:right
- android:bottom
- size
- 表示shape的固有大小 设置后
getIntrinsicWidth
和getIntrinsicHeight
就不是默认的-1了 - android:width
- android:height