Shape的子属性
- 属性 - 描述
- solid - 给shape填充背景颜色
- gradient - 给shape添加背景渐变
- stroke - 给shape添加边框
- corners - 给shape添加圆角
- padding - 给shape设置上下左右四个方向的间隔
- size - 给shape设置大小
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<!-- oval表示椭圆 可以指定的形状有四种: line线形、oval椭圆形、ring环形、rectangle距形 -->
<!-- 填充 -->
<solid android:color="#ffffff" /> <!-- 定义填充的颜色值 填充的颜色,它也就只有这一个属性值-->
<!-- 渐变 (注意如果将solid的颜色设置为透明,则gradient的设置将失效)-->
<gradient
android:angle="90" <!-- 渐变角度,必须是45的整数倍 -->
android:endColor="#00ff00" <!-- 渐变结束的颜色 -->
android:startColor="#ff0000" <!-- 渐变开始的颜色 -->
android:type="sweep" /> <!-- 渐变属性 以中心为原点360度扫描式渐变模式
默认的渐变模式为 linear 线性渐变 ,还有一种为径向渐变 radial ,在使用径向渐变时还需要额外设定半径 android:gradientRadius -->
<!-- 描边 -->
<stroke
android:width="10dp" <!-- 描边线宽 -->
android:color="#0000ff" <!--描边线的颜色 -->
android:dashGap="3dp" <!-- 间隔的距离 -->
android:dashWidth="5dp" /> <!-- 表示'-'这样一个横线的宽度 -->
<!-- 圆角 -->
<corners
<!-- android:radius="5dp" 圆角的半径,值越大角越圆-->
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" /> <!-- 单独设置四个角的半径 -->
<!-- 间隔 -->
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" /> <!-- 设置各个方向的间隔 -->
<!-- 大小 -->
<size
android:width="300dp"
android:height="200dp" /> <!-- 定义宽高 -->
</shape>