简体   繁体   English

是否可以在Android中以弧形创建进度条?

[英]Is it possible to create a progressbar in arc shape in android?

I need to create a progressbar in arc shape. 我需要创建一个弧形的进度条。 should I create a custom view for that? 我应该为此创建一个自定义视图吗? Or with the help of onDraw() method of ProgressBar class I can perform this thing? 还是借助ProgressBar类的onDraw()方法,我可以执行此操作? I also want to add marker on this progressBar like thermometer. 我也想在此progressBar上添加标记,例如温度计。 Please suggest me any idea. 请给我建议任何想法。 Thanks. 谢谢。

Something like this: 像这样:

protected synchronized void onDraw(Canvas canvas) {

    int progress = this.getProgress();
    int maxProgress = this.getMax();

    //calc the progress to angles 
    float angleProgress = progress * 360 / maxProgress;

    //create and set the arc paint 
    Paint arcPaint = new Paint(); 
    arcPaint.setColor(0xff800000); 
    arcPaint.setAntiAlias(true); 
    arcPaint.setStyle(Style.FILL);

    Rect arcRect = new Rect(); this.getDrawingRect(arcRect);
    canvas.drawArc(new RectF(arcRect), -90, angleProgress,true, arcPaint); 
}

For ref check this image arc shape progressbar 对于参考检查此图像弧形进度条 http://i.stack.imgur.com/FY0dq.png

The default ProgressBar widget is not easily customisable, even for significantly less ambitious changes than this. 默认的ProgressBar窗口小部件不容易自定义,即使远没有那么大的更改。 In my opinion, it offers you no valuable behaviours in this context, other than acting as a carrier for minimum, maximum and current values. 我认为,除了充当最小值,最大值和当前值的载体外,它在这种情况下没有提供任何有价值的行为。 It also brings with it unwanted functionality such as the 'indeterminate' state. 它还带来了不需要的功能,例如“不确定”状态。

Create a custom view by extending View and implementing onDraw() - as you have - and onMeasure(). 通过扩展View并实现onDraw()-和onMeasure()来创建自定义视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM