在Android帆布中,如何绘制一个圆并沿圆圈移动对象,并在圆圈中间显示圆的百分比



我想要这个示例

请帮助我...在此处输入图像描述

在您的布局中包含以下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。与上面的示例不同,它提供了平稳的动画。

最新更新