您知道如何制作类似Google Fit应用程序中的圆形进度条吗?就像下面的图片一样。
您知道如何制作类似Google Fit应用程序中的圆形进度条吗?就像下面的图片一样。
你可以轻松自己创建这个
在你的布局中,包含以下具有特定可绘制对象的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
)和厚度数值。
圆形(适用于Lollipop之前或API级别小于21)
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:thickness="3.8sp" >
<solid android:color="@color/yourColor" />
</shape>
循环(>= Lollipop 或 API 级别 >= 21)
<shape
android:useLevel="true"
android:innerRadiusRatio="2.3"
android:shape="ring"
android:thickness="3.8sp" >
<solid android:color="@color/yourColor" />
</shape>
< p > useLevel 在 API Level 21(Lollipop)中默认为"false"。
开始动画
接下来在您的代码中使用ObjectAnimator
对您布局中的 ProgressBar
的进度字段进行动画处理。
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();
附言:与上面的例子不同,它提供了流畅的动画效果。
shape
元素之前使用 rotate
元素。 - Murtaza Khursheed HussainDonutProgress:
<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"/>
圆形进度条:
<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"/>