当前位置: 首页 > 知识库问答 >
问题:

如何让ProgressBar停止旋转?

束俊材
2023-03-14

当我添加水平进度条时,它的行为和预期的一样——我设置了进度值并显示了它。

但是,当我添加ProgressBar(圆形)时,它会旋转。就这样。在这种形式下,更多的是“请等待”指示器,即任何进度条,因为没有显示进度值。

所以我的问题是(假设名义上的进步意味着进步)——如何停止旋转并显示进步的价值?例如,如果我将max设置为100,将value设置为50,我希望看到半圆弧。

换句话说,如何使圆形的ProgressBar表现得像水平的ProgressBar,只有形状例外?

共有3个答案

郝修为
2023-03-14

就像toadzky评论的那样,没有烘焙方法。你可以试试这个轮子。如果没有其他东西,它应该让你知道如何实现它。

韦繁
2023-03-14

由于API21您可以这样做:假设您的ProgressBar定义如下:

 <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/progressBarStyleLarge"
    android:id="@+id/progress_bar"
    android:layout_width="@dimen/item_width"
    android:layout_height="@dimen/item_height"
    android:clickable="false"
    android:indeterminate="true"
    android:indeterminateDrawable="@drawable/progress"/>

这是progress.xml

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

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

    <gradient
        android:angle="0"
        android:endColor="@color/colorGrayText"
        android:startColor="@android:color/transparent"
        android:type="sweep"
        android:useLevel="false" />

</shape>

现在,您可以在进度条上执行此操作:

 ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
        if (progressBar != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                RotateDrawable rotateDrawable = (RotateDrawable) progressBar.getIndeterminateDrawable();
                rotateDrawable.setToDegrees(0);
            }
        }

谭毅然
2023-03-14

我知道这是一个老帖子,但我遇到了同样的问题,我让它工作。

实际上,这比您想象的要容易,您必须在可绘制文件夹中的xml文件中设置一个自定义进度,并处理属性“fromDegrees”和“toDegrees”

这是自定义进程的代码。xml(您可以根据自己的喜好进行自定义,但不能修改“fromDegrees”和“toDegrees”)

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape
            android:innerRadiusRatio="2.3"
            android:shape="ring"
            android:useLevel="false"
            android:type="sweep"
            android:thicknessRatio="15.0">
            <solid android:color="#0099ff"/>
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <rotate
            android:pivotX="50%"
            android:pivotY="50%"
            android:fromDegrees="-90"
            android:toDegrees="-90">
            <shape
                android:innerRadiusRatio="2.3"
                android:shape="ring"
                android:angle="0"
                android:type="sweep"
                android:thicknessRatio="15.0">
                <solid android:color="#e0e0e0"/>
            </shape>
        </rotate>
    </item>
</layer-list>

对于进度条,您必须设置以下属性:

<ProgressBar
    android:id="@+id/progressbar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:indeterminate="false"
    android:max="100"
    android:progress="20"
    android:progressDrawable="@drawable/custom_progress" />

这里发生的事情是,进度将以90度开始,对我来说,90度是进度条视图的顶部,向右,它将继续朝着相同的度,这将使视图以相同的度开始和结束。

注意:如果将“fromDegrees”和“toDegrees”都设置为0,则进度将从圆圈的右侧开始。

希望它能帮助有同样需求的人。

 类似资料:
  • 我无法停止。它的样式是。如何启动和停止圆形的小型?

  • 默认情况下,当Storm喷口或螺栓遇到异常时,它会重新启动喷口或螺栓,然后再试一次。是否有任何配置选项使它停止拓扑,也许在N次重复尝试之后?(例如,Hadoop尝试了4次才放弃。) 我有一个Storm拓扑运行了77天,一个螺栓在每个元组上引发一个异常。在这种情况下,我宁愿它失败,这样我就会注意到有问题。

  • 问题内容: 该程序在九次打印后完成: 如何停止进程(例如eclipse中的Java进程),因为它在9秒的时间限制后没有停止? 问题答案: 您遇到的问题是,取消哔声任务后,调度程序会保留活动线程。 如果存在活动的非守护程序线程,则JVM保持活动状态。 它使该线程保持不变的原因是您已在此行中告诉它这样做: 请注意以下文档: -即使在空闲状态下要保留在池中的线​​程数。 因此,您有两种可能的方法来导致J

  • 问题内容: 我有一个goroutine,它调用一个方法,并在通道上传递返回的值: 如何停止这种goroutine? 问题答案: 编辑: 在意识到您的问题是关于将值发送到goroutine中的chan之前,我匆忙编写了此答案。 下面的方法可以与上面建议的其他chan一起使用,或者利用您已经拥有的chan双向的事实,您可以只使用一个… 如果您的goroutine仅用于处理来自chan的项目,则可以使用

  • 问题内容: 要找出mysqld的启动命令(使用Mac),我可以这样做: 我得到以下输出,这使我可以启动mysql服务器。 我如何找到必要的命令以从命令行停止mysql? 问题答案: 尝试: 要么: 要么: 要么: 如果 在OSX中 安装 Launchctl,则 可以尝试: MacPorts 注意:重新启动后,此设置将持续存在。 家酿 二进制安装程序 我发现在:https : //stackover

  • 问题内容: 如何停止块枚举? 我知道在obj-c中,您可以这样做: 问题答案: 在Swift 1中: 在Swift 2中: 在Swift 3-4中: