为了账号安全,请及时绑定邮箱和手机立即绑定

如何在android中创建循环ProgressBar?

如何在android中创建循环ProgressBar?

慕沐林林 2019-07-25 15:50:15
如何在android中创建循环ProgressBar?您是否知道如何制作像Google Fit应用程序一样的循环进度条?
查看完整描述

2 回答

?
九州编程

TA贡献1785条经验 获得超4个赞

您可以尝试这个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"/>


查看完整回答
反对 回复 2019-07-25
?
PIPIONE

TA贡献1829条经验 获得超9个赞

自己创建这个很容易

在您的布局中包含以下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" />

现在使用以下形状在资源中创建drawable。使用半径(您可以使用innerRadius而不是innerRadiusRatio)和厚度值进行游戏。

循环(Pre Lollipop OR API Level <21)

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

圆形(> = Lollipop OR API Level> = 21)

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

默认情况下,API Level 21(Lollipop)中的useLevel“false”

开始动画

在代码中接下来使用an ObjectAnimatorProgessBar为布局的progress字段设置动画。

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 valueanimation.setDuration(5000); // in millisecondsanimation.setInterpolator(new DecelerateInterpolator());animation.start();

停止动画

progressBar.clearAnimation();

PS不同于上面的例子,它给出了流畅的动画。


查看完整回答
反对 回复 2019-07-25
  • 2 回答
  • 0 关注
  • 761 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信