可以定制一些简单的路径,按想要的绘制顺序添加,SimpleLineView会依次展现路径动画。
这里简单借鉴了OkHttp的责任链模式,整体架构图如下:
dependencies {
implementation 'com.robog:SimpleLineView:1.0.3'
}
// 圆形
PixelPath circlePath = new PixelPath(10, 10, new int[]{1, 100});
CirclePainter ciclePainter = new RealCirclePainter(circlePath, 1000, -120, 360, false);
// 矩形
PixelPath squarePath = new PixelPath(2, 2, new int[]{1, 2, 4, 3});
Painter squarePainter = new SegmentPainter(squarePath, 1000, true);
mView.addPainter(ciclePainter).addPainter(squarePainter);
// 启动
mView.start();
// 停止
mView.stop();
// 继续
mView.stick();
以4 * 4的表格为例
1 | 2 | 3 | 4 |
---|---|---|---|
5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 |
如果path为{1, 13, 16, 4}, 则绘制的图形为依次连接1,13,16,4的矩形(是否封闭可设置对应参数)。
如果图形的形状比较复杂,可以用PS打开图片,依次获取像素点的x和y值(这里x和y值的单位可以是像素、厘米等,但是计算时要与图像大小的单位一致)。假设图像宽为w, 高为h, 则当前点的值为 w * ( y - 1) + x。