c# xamarin 圆形进度条 - Android

c# xamarin circular progress bar - Android

创建了一个与动画配合良好的圆形进度条。但是在尝试使用动态数据进度条显示它时没有更新。

以下代码有效

  progrssBarObj = FindViewById<ProgressBar>(Resource.Id.progressBarSync);

  ObjectAnimator animation = ObjectAnimator.OfInt(progrssBarObj, "progress", 0, 100); // see this max value coming back here, we animale towards that value
  animation.SetDuration(3000); //in milliseconds
  animation.SetInterpolator(new DecelerateInterpolator());
  animation.Start();

AXML 代码是

<ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_column="2"
            android:id="@+id/progressBarSync"
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:progressDrawable="@drawable/circular_progress_bar"
            android:background="@drawable/progress_bar_background" />

但是当我在循环中尝试类似的操作时,进度条没有随数据更新。基本上进度条不是循环更新的。

           for (int i = 0; i <= 100; i++)
            {
                int cnt = 0;
                cnt = cnt + i;
                progrssBarObj.Progress = cnt;

            }

我们将不胜感激。

我在新任务中保留了 for 循环,它成功了

await Task.Run(() =>
{
  for (int i = 0; i < dtITM.Rows.Count; i++)
  {
    int cnt = 0;
    cnt = cnt + i;
    progrssBarObj.Progress = cnt;
  }
}