如何使用Java在Android中更改ProgressBar的速度?

y53ybaqx  于 2023-11-15  发布在  Android
关注(0)|答案(1)|浏览(147)

我有一个ProgressBar(圆形的),它旋转得非常快,我如何改变它以较慢的速度旋转?
(It无限期运行)
下面是我的ProgressBar的XML:

  1. <ProgressBar
  2. android:id="@+id/progressBar"
  3. style="@style/Widget.AppCompat.ProgressBar"
  4. android:layout_width="409dp"
  5. android:layout_height="710dp"
  6. android:indeterminate="false"
  7. android:padding="36dp"
  8. app:layout_constraintBottom_toBottomOf="parent"
  9. app:layout_constraintEnd_toEndOf="parent"
  10. app:layout_constraintStart_toStartOf="parent"
  11. app:layout_constraintTop_toTopOf="parent" />

字符串

zbdgwd5y

zbdgwd5y1#

在/drawable路径下添加一个.xml文件,如:drawable/circular_spinner.xml circular_spinner:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <rotate xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:drawable="@drawable/spinner"
  4. android:interpolator="@android:anim/linear_interpolator"
  5. android:fromDegrees="0"
  6. android:pivotX="50%"
  7. android:pivotY="50%"
  8. android:repeatCount="infinite"
  9. android:toDegrees="3600"
  10. android:duration="1000"/>

字符串
更改toDegreesduration来控制旋转的速度。然后在progressbar布局中调用它。

  1. <ProgressBar
  2. android:id="@+id/progressBar"
  3. style="@style/Widget.AppCompat.ProgressBar"
  4. android:layout_width="409dp"
  5. android:layout_height="710dp"
  6. android:indeterminate="false"
  7. android:padding="36dp"
  8. app:layout_constraintBottom_toBottomOf="parent"
  9. app:layout_constraintEnd_toEndOf="parent"
  10. app:layout_constraintStart_toStartOf="parent"
  11. android:indeterminateDrawable="@drawable/circular_spinner"
  12. app:layout_constraintTop_toTopOf="parent"/>

展开查看全部

相关问题