我想要这个示例
请帮助我...在此处输入图像描述
在您的布局中包含以下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
(和厚度值。
圆形(pre Lollipop或API级别&lt; 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>
USELEVEL 是" false" 默认为API级别21(Lollipop(。
开始动画
代码中的下一个使用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 animale towards that value
animation.setDuration (5000); //in milliseconds
animation.setInterpolator (new DecelerateInterpolator ());
animation.start ();
停止动画
progressBar.clearAnimation();
P.S。与上面的示例不同,它提供了平稳的动画。