进度指示器

发布于 2024-08-29 10:46:40 字数 57 浏览 1 评论 0原文

有什么办法可以让进度条变成圆形吗?我的应用程序中有一个播放按钮,并且想在按钮周围显示加载歌曲的进度。

Is there any way to make the progress bar into a circle shape? I have a play button in my apps and would like to show the progress of loading the song around the button.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扬花落满肩 2024-09-05 10:46:40

ProgressBar 小部件有两种影响其外观的模式:

  • 在进度模式下,您会得到一条直线,您可以在前进时设置进度值
  • 在不确定模式下,您会得到一个旋转的圆形动画,直到您停止为止

我最近构建了一个倒计时进度指示器,我希望一个盒子能够像时钟一样随着时间的流逝而倒退。这听起来很像你想做的事情,只是相反。

我所做的是创建我自己的 View 子类。然后在 onDraw() 重写中,我直接在画布上绘画。这听起来可能很麻烦,但它确实很简单,而且实际上可以控制整个绘画过程。

像这样绘制整个盒子......

@Override
public void onDraw(Canvas canvas) {
    Rect rect = canvas.getClipBounds();
    rect.inset(10f, 10f);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Join.ROUND);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(10f);
    canvas.drawRect(countdownRect, paint);
}

有很多绘制方法可以用来绘制其他形状,线条,路径,圆形等。

The ProgressBar widget has two modes which affect how it looks:

  • In progress mode, you get the straight line where you can set the progress value as you go along
  • In indeterminate mode, you get a circular animation that spins until you stop it

I recently built a countdown progress indicator where I wanted a box to "unwind" like a clock going backwards as time ticked down. This sounds very much like what you want to do, only in reverse.

What I did was create my own class that subclasses View. Then in my onDraw() override I painted directly on the canvas. It might sound like too much trouble, but it's really easy and actually kinda controlling the whole painting process.

Something like this to draw the box all the way around...

@Override
public void onDraw(Canvas canvas) {
    Rect rect = canvas.getClipBounds();
    rect.inset(10f, 10f);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Join.ROUND);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(10f);
    canvas.drawRect(countdownRect, paint);
}

...there are plenty of draw methods you can use to draw other shapes, lines, paths, circles, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文