如何设置圆形不定进度条的粗细android?
How to set thickness of circular indeterminate progress bar android?
我有两个嵌套的圆形不确定进度条,但我无法将它们的粗细设置为相等的大小。我尝试使用形状对其进行自定义。但是,这会删除循环不确定进度的默认行为。
我这样自定义,它使厚度相等但没有得到默认行为。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<rotate android:toDegrees="360">
<shape
android:shape="ring"
android:thickness="4dp">
<solid android:color="@color/white" />
</shape>
</rotate>
</item>
</layer-list>
<ProgressBar
android:id="@+id/download_progress4"
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_gravity="center"
android:indeterminate="true"
android:indeterminateDrawable="@style/ProgressThem" />
我想要这样的循环不确定进度条的默认行为
试试这个
使用
android:innerRadiusRatio="3"
android:thicknessRatio="20.0
示例代码
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<rotate android:toDegrees="360">
<shape
android:shape="ring"
android:thickness="4dp"
android:innerRadiusRatio="3"
android:thicknessRatio="20.0">
<solid android:color="@color/white" />
</shape>
</rotate>
</item>
</layer-list>
如果您想要现代动画而不仅仅是旋转,您可以复制并更改 https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/drawable/progress_indeterminate_anim_medium_material.xml 将其用作 indeterminateDrawable
。
<ProgressBar
android:indeterminateDrawable="@drawable/new_progress_indeterminate_anim_medium_material"
例如更改 vector_drawable_progress_bar_medium.xml android:strokeWidth="1"
中的宽度。
这样做有点痛苦,因为您还需要将动画、插值器和动画制作器 xml 文件复制到您的项目中,因为它们在 Android SDK 中是私有的。
实际上有一种更简单的方法可以使用 material 组件来做到这一点:
<com.google.android.material.progressindicator.CircularProgressIndicator
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
app:trackThickness="3dp" />
material 文档中的更多详细信息 -> https://material.io/components/progress-indicators/android#circular-progress-indicators
我有两个嵌套的圆形不确定进度条,但我无法将它们的粗细设置为相等的大小。我尝试使用形状对其进行自定义。但是,这会删除循环不确定进度的默认行为。 我这样自定义,它使厚度相等但没有得到默认行为。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<rotate android:toDegrees="360">
<shape
android:shape="ring"
android:thickness="4dp">
<solid android:color="@color/white" />
</shape>
</rotate>
</item>
</layer-list>
<ProgressBar
android:id="@+id/download_progress4"
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_gravity="center"
android:indeterminate="true"
android:indeterminateDrawable="@style/ProgressThem" />
我想要这样的循环不确定进度条的默认行为
试试这个
使用
android:innerRadiusRatio="3"
android:thicknessRatio="20.0
示例代码
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<rotate android:toDegrees="360">
<shape
android:shape="ring"
android:thickness="4dp"
android:innerRadiusRatio="3"
android:thicknessRatio="20.0">
<solid android:color="@color/white" />
</shape>
</rotate>
</item>
</layer-list>
如果您想要现代动画而不仅仅是旋转,您可以复制并更改 https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/drawable/progress_indeterminate_anim_medium_material.xml 将其用作 indeterminateDrawable
。
<ProgressBar
android:indeterminateDrawable="@drawable/new_progress_indeterminate_anim_medium_material"
例如更改 vector_drawable_progress_bar_medium.xml android:strokeWidth="1"
中的宽度。
这样做有点痛苦,因为您还需要将动画、插值器和动画制作器 xml 文件复制到您的项目中,因为它们在 Android SDK 中是私有的。
实际上有一种更简单的方法可以使用 material 组件来做到这一点:
<com.google.android.material.progressindicator.CircularProgressIndicator
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
app:trackThickness="3dp" />
material 文档中的更多详细信息 -> https://material.io/components/progress-indicators/android#circular-progress-indicators