安卓自定义控件-手表

1.效果展示

2.手表控件

2.1表盘实现

画圆形表盘的条件

float centerX = getWidth() / 2.0f;//圆心X坐标
float centerY = getWidth() / 2.0f;//圆心Y坐标
float radius = getWidth() / 2.0f - 10;//半径(1/2宽稍微偏移一点,给圆盘留一些绘制宽度)

用canvas绘制圆形表盘

public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint);

Draw the specified circle using the specified paint. If radius is <= 0, then nothing will be
drawn. The circle will be filled or framed based on the Style in the paint.

@param cx The x-coordinate of the center of the circle to be drawn
@param cy The y-coordinate of the center of the circle to be drawn
@param radius The radius of the circle to be drawn
@param paint The paint used to draw the circle

猜你喜欢

转载自blog.csdn.net/mozushixin_1/article/details/125204863