Shape的使用
Shape基础知识
Shape支持图形:
1、rectangle
2、oval
3、line
4、ring
Shape常用属性含义
属性名称 | 属性含义 | 用处 |
---|---|---|
corners | 角 | shape = rectangle时使用,可以用来绘制圆角矩形 |
size | 大小 | 为这个shape指定大小,一般在ImageView配合ScaleType使用 |
gradient | 渐变 | 无限制 |
solid | 颜色填充 | 无限制 |
stroke | 线条 | 无限制 |
gradient与oval
效果图
从上到下:辐射渐变 radial,线性渐变 linear,sweep,雷达扫描渐变
shape_oval_with_gradient
<?xml version="1.0" encoding="utf-8"?>
<!--
shape:oval
渐变:辐射渐变 radial(必须设置gradientRadius)
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:startColor="@color/colorAccent"
android:endColor="@android:color/white"
android:type="radial"
android:gradientRadius="50dp"
>
</gradient>
<size
android:width="100dp"
android:height="100dp"/>
</shape>
shape_oval_with_gradient1
<?xml version="1.0" encoding="utf-8"?>
<!--
shape:oval
渐变:线性渐变 linear, angle指的是渐变方向角(只对linear有效)
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:angle="45"
android:centerX="0.5"
android:centerY="0.5"
android:startColor="@android:color/white"
android:centerColor="@color/colorAccent"
android:endColor="@android:color/white"
android:type="linear"
>
</gradient>
<size
android:width="100dp"
android:height="100dp"/>
</shape>
shape_oval_with_gradient2
<?xml version="1.0" encoding="utf-8"?>
<!--
shape:oval
渐变:sweep,雷达扫描渐变
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"