SHapeDrawable 通过颜色来构造图形。通过xml构建。
1.建立文件
在res文件里新建drawable文件,标签为shape
2.标签详解
- shape表示图形文件
rectangle 矩形
oval 椭圆
line 横线
ring 圆环
ring标签有额外属性
corners表示shape的四个角
gradient 渐变色填充
solid纯色填充
stroke描边
padding 背景空白
size固有大小(可省略)
3.例子
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
// rectangle \ oval \ line \ ring
//corners 四个角度
<corners
android:radius="3dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="7dp"
android:topRightRadius="8dp"
/>
//渐变色
<gradient
android:angle="45dp"
android:centerX="30dp"
android:centerY="20dp"
android:startColor="#000"
android:centerColor="#fff"
android:endColor="#555"
android:gradientRadius="30dp"
android:useLevel="false"
android:type="radial"
/>
//solid 纯色填充
<solid
android:color="#ccc"
/>
//stroke shape描边
<stroke
android:color="#fff"
android:dashWidth="3dp"
android:dashGap="30dp"
android:width="3dp"
/>
//padding 背景空白大小
<padding
android:left="3dp"
android:bottom="3dp"
android:right="2dp"
android:top="4dp"
/>
//size 固有宽度 高度
<size
android:width="300dp"
android:height="300dp"
/>
</shape>