如何在android中创建循环ProgressBar?您是否知道如何制作像Google Fit应用程序一样的循环进度条?
2 回答
![?](http://img1.sycdn.imooc.com/54584c910001b8d902200220-100-100.jpg)
九州编程
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"/>
![?](http://img1.sycdn.imooc.com/545863e80001889e02200220-100-100.jpg)
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 ObjectAnimator
来ProgessBar
为布局的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不同于上面的例子,它给出了流畅的动画。
- 2 回答
- 0 关注
- 761 浏览
添加回答
举报
0/150
提交
取消