【问题标题】:How to create circular ProgressBar in android? [closed]如何在android中创建圆形ProgressBar? [关闭]
【发布时间】:2015-01-28 13:44:11
【问题描述】:

您知道如何制作类似于 Google Fit 应用程序的圆形进度条吗?如下图。

【问题讨论】:

  • 我最近确实做了这样的事情。这可能是一个有用的起点? github.com/daentech/CircularDemo
  • @daentech 太棒了!谢谢
  • 有人得到答案,加载部分的边缘像示例中那样是圆形的吗?
  • @Siebe 您可以使用我在回答中提到的库。可以根据需要对其进行自定义以获取加载部分。
  • 也许这可以为您指明正确的方向github.com/grmaciel/two-level-circular-progress-bar

标签: android android-progressbar


【解决方案1】:

自己创建很容易

在您的布局中包含以下带有特定可绘制对象的ProgressBar请注意,您应该改为从尺寸中获取宽度)。最大值在这里很重要:

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:max="500"
    android:progress="0"
    android:progressDrawable="@drawable/circular" />

现在使用以下形状在您的资源中创建可绘制对象。使用半径(您可以使用innerRadius 而不是innerRadiusRatio)和厚度值。

循环(棒棒糖前或 API 级别

   <shape
        android:innerRadiusRatio="2.3"
        android:shape="ring"
        android:thickness="3.8sp" >
        <solid android:color="@color/yourColor" />
   </shape>

循环(>= Lollipop OR API 级别 >= 21)

    <shape
        android:useLevel="true"
        android:innerRadiusRatio="2.3"
        android:shape="ring"
        android:thickness="3.8sp" >
        <solid android:color="@color/yourColor" />
     </shape>

useLevel 在 API 级别 21 (Lollipop) 中默认为 "false"

开始动画

接下来在您的代码中使用ObjectAnimator 为布局的ProgessBar 的进度字段设置动画。

ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", 0, 500); // see this max value coming back here, we animate towards that value
animation.setDuration(5000); // in milliseconds
animation.setInterpolator(new DecelerateInterpolator());
animation.start();

停止动画

progressBar.clearAnimation();

附:与上面的示例不同,它提供了流畅的动画效果。

【讨论】:

  • 步骤在那里,如果你遵循这个,99% 肯定你会得到结果。
  • 像魅力一样工作。希望我能不止一次地对此表示赞同
  • 对我不起作用,视图不可见
  • 我不知道你在做什么,视图不可见不是完整的问题描述
  • 您的答案看起来可能效果很好.. 但是一张图片 = 1000 个字.. 因此,如果您将输出添加为屏幕截图,它可能对未来的用户有用 - 恕我直言
【解决方案2】:

你可以试试这个Circle Progress

注意:请始终为进度视图使用相同的宽度和高度

DonutProgress:

 <com.github.lzyzsd.circleprogress.DonutProgress
        android:id="@+id/donut_progress"
        android:layout_marginLeft="50dp"
        android:layout_width="100dp"
        android:layout_height="100dp"
        custom:circle_progress="20"/>

CircleProgress:

  <com.github.lzyzsd.circleprogress.CircleProgress
        android:id="@+id/circle_progress"
        android:layout_marginLeft="50dp"
        android:layout_width="100dp"
        android:layout_height="100dp"
        custom:circle_progress="20"/>

ArcProgress:

<com.github.lzyzsd.circleprogress.ArcProgress
        android:id="@+id/arc_progress"
        android:background="#214193"
        android:layout_marginLeft="50dp"
        android:layout_width="100dp"
        android:layout_height="100dp"
        custom:arc_progress="55"
        custom:arc_bottom_text="MEMORY"/>

【讨论】:

  • 他们如何显示正在进行的值我正在尝试 setProgress in on protected void onProgressUpdate() { super.onProgressUpdate(); Log.d(TAG, "onProgressUpdate"); progressBar.setProgress(progressBar.getProgress() + j); Log.d(TAG, "onProgressUpdate perc:" + j); updateMemoryAndCountValues(); } 但它不工作
  • @Top Cat 如何添加动画,例如放大圆圈进度或mikinw.blogspot.com/2013/03/glow-effect.html
  • 最佳许可证
  • WTF 许可证。哈哈。
  • 获取未绑定前缀错误
猜你喜欢
  • 1970-01-01
  • 2021-07-02
  • 1970-01-01
  • 2020-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多