0%

可绘制的形状背景

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
1️⃣ rectangle(矩形)

最常用的形状。

可以通过 cornerRadius 设置圆角。

示例:

<shape android:shape="rectangle">
<solid android:color="#FF0000"/>
<corners android:radius="8dp"/>
</shape>

2️⃣ oval(椭圆 / 圆)

如果宽高相等就是圆形。

可用于圆形按钮或头像背景。

3️⃣ line(直线)

表示一条线,需要设置 size 的 height 或 width 才能显示。

示例:

<shape android:shape="line">
<size android:height="2dp"/>
<solid android:color="#000000"/>
</shape>

4️⃣ ring(环 / 圆环)

用于画圆环或进度条背景。

需要设置 innerRadius(内半径)、thickness(环宽)。

示例:

<shape android:shape="ring">
<size android:width="100dp" android:height="100dp"/>
<solid android:color="#00FF00"/>
<ring
android:innerRadius="30dp"
android:thickness="10dp"/>
</shape>

⚡ 总结
形状 说明 用途示例
rectangle 矩形,可加圆角 按钮、背景、卡片
oval 椭圆或圆 圆形按钮、头像
line 一条直线 分割线
ring 圆环 环形进度条