/
ShapeUtil.java
79 lines (72 loc) · 2.41 KB
/
ShapeUtil.java
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.liyi.sutils.utils.graphic;
import android.graphics.drawable.GradientDrawable;
/**
* Shape 工具类
*/
public final class ShapeUtil {
/**
* 绘制圆角矩形 drawable
*
* @param fillColor 图形填充色
* @param radius 图形圆角半径
* @return 圆角矩形
*/
public static GradientDrawable drawRoundRect(int fillColor, int radius) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setColor(fillColor);
shape.setCornerRadius(radius);
return shape;
}
/**
* 绘制圆角矩形 drawable
*
* @param fillColor 图形填充色
* @param radius 图形圆角半径
* @param strokeWidth 边框的大小
* @param strokeColor 边框的颜色
* @return 圆角矩形
*/
public static GradientDrawable drawRoundRect(int fillColor, int radius, int strokeWidth, int strokeColor) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setColor(fillColor);
shape.setCornerRadius(radius);
shape.setStroke(strokeWidth, strokeColor);
return shape;
}
/**
* 绘制圆角矩形 drawable
*
* @param fillColor 图形填充色
* @param radii 图形圆角半径
* @param strokeWidth 边框的大小
* @param strokeColor 边框的颜色
* @return 圆角矩形
*/
public static GradientDrawable drawRoundRect(int fillColor, float[] radii, int strokeWidth, int strokeColor) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setColor(fillColor);
shape.setCornerRadii(radii);
shape.setStroke(strokeWidth, strokeColor);
return shape;
}
/**
* 绘制圆形
*
* @param fillColor 图形填充色
* @param size 图形的大小
* @param strokeWidth 边框的大小
* @param strokeColor 边框的颜色
* @return 圆形
*/
public static GradientDrawable drawCircle(int fillColor, int size, int strokeWidth, int strokeColor) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.OVAL);
shape.setSize(size, size);
shape.setColor(fillColor);
shape.setStroke(strokeWidth, strokeColor);
return shape;
}
}