要在Android中绘制圆圈和饼图,我们可以使用AChartEngine所示的here Android框架。
但是,我们如何在Android中绘制部分水平(或垂直)填充的圆圈?我指的是根据Java代码中指定的百分比从例如从底部到顶部填充的圆圈。
以下是我们需要的预览:
答案 0 :(得分:7)
试试这个lib Circle Progress 以下是来自lib的作者的样本:
let waitAndPrint = SKAction.customActionWithDuration(3) {
_, elapsedTime in
// prints about every second
if (elapsedTime % 1 < 0.018) {
println("tipped")
}
}
答案 1 :(得分:0)
扩展Drawable
并让您的draw
方法看起来像这样:
public void draw(Canvas c) {
float size = ...; // The size of your circle
Paint color = new Paint();
color.setColor(...); // Color of your circle
c.drawCircle(size / 2, size / 2, size / 2, color);
Path p = new Path();
float ratio = ...; // How many of the circle you want to have filled
float offset = size * (float) Math.sqrt(1-((double) (0.5-ratio) * 2)*((double) (0.5-ratio) * 2)) / 2;
float angle = (float) Math.asin((double) (0.5-ratio) * 2);
p.addArc(offset, size * (1-percent), size - offset, size, angle, Math.PI - angle);
p.close();
c.drawPath(p, color);
}