android - 如何重新创建进度条旋转?

标签 android android-progressbar

如何重新创建 progressBarStyleLarge 类型的 ProgressBar 的旋转?

我有这样的布局:

<androidx.core.widget.ContentLoadingProgressBar
    android:id="@+id/loadingIndicator"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:indeterminateDrawable="@drawable/loadingindicator"
    style="?android:attr/progressBarStyleLarge" />

可绘制loadingindicator:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="0"
    android:toDegrees="360" >

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="40"
        android:useLevel="false" >

        <size
            android:height="48dip"
            android:width="48dip" />

        <gradient
            android:startColor="#ff00ff"
            android:centerColor="#ff00ff"
            android:endColor="#ffffff"
            android:centerY="0.50"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>

但这会导致平滑的恒定旋转,而不是 - 我相信 - 以默认样式显示的 2 个平行旋转。

具体来说,我想重新创建 Indeterminate circular progress indicator 的动画,如下所示: https://material.io/components/progress-indicators/#circular-progress-indicators

XY问题披露: 我需要这个,因为我想自定义 ProgressBar 的笔画粗细和外边距。

最佳答案

您可以在如下代码中使用 CircularProgressDrawable:

val drawable = CircularProgressDrawable(context).apply {
    strokeWidth = // desired width in pixels
}
progressBar.indeterminateDrawable = drawable

文档: https://developer.android.com/reference/android/support/v4/widget/CircularProgressDrawable

关于android - 如何重新创建进度条旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59061879/

相关文章:

android - Otto for Android 就像 Go-to

java - 使用媒体播放器更新进度条

java - ProgressBar 在 RecyclerView Adapter 中不刷新

android - 如何将 ProgressBar 的样式更改为小?

android - 向上滚动时自定义 ListView 然后隐藏进度条进程

android - 初始化 Drawable 时出现 ResourcesNotFoundException

Android:ListView 中的自定义分隔符(甚至是项目)取决于项目的内容

android - 手机上的文本缩放

android - Cordova 插件的输出延迟

安卓 : Semi Circle Progress Bar