繁体   English   中英

如何设置圆形不确定进度条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 中是私有的。

实际上有一种更简单的方法可以使用材料组件来做到这一点:

<com.google.android.material.progressindicator.CircularProgressIndicator
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        app:trackThickness="3dp" />

材料文档中的更多详细信息-> https://material.io/components/progress-indicators/android#circular-progress-indicators

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM