Android - 圆形进度条不起作用

Android - Circular progress bar not working

我正在尝试创建一个不确定的进度条来表示我的应用正在加载。然而,在尝试了无数 xml 布局和不同的代码位之后,我似乎无法使任何工作正常进行。这是我的主要片段的 xml 文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             tools:context="com.example.dwinnbrown.xxx.FirstFragment">

    <!-- TODO: Update blank fragment layout -->
        <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />

    <ProgressBar
        android:id="@+id/prgrsbar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:max="500"
        android:progress="0"
        android:indeterminate="true"
        android:progressDrawable="@drawable/circular" />


</FrameLayout>

还有我的 circular.xml 文件:

<shape
    android:innerRadiusRatio="3"
    android:shape="ring"
    android:thicknessRatio="7.0">

    <gradient
        android:centerColor="#007DD6"
        android:endColor="#007DD6"
        android:startColor="#007DD6"
        android:angle="0"
        android:type="sweep"
        android:useLevel="false" ></gradient>
</shape>

但是输出是这样的——我是不是漏掉了什么?

我去进度条了,不过还有一点需要先改进:

FrameLayout 适用于相互堆叠的子项,但不支持对齐其中的视图。

因此,一个简单的开始是使用 Relativelayout 作为根视图,然后您可以轻松地将 Progressbar 对齐到视图的中间。

现在,到进度条,我自己还没有完成你的用例。但我建议您先将其剥离到最基本的部分,看看它是否已显示,所以:

<ProgressBar
    android:id="@+id/prgrsbar"
    android:layout_width="150dp"
    android:layout_centerInParent="true"
    android:layout_height="150dp"/>

这应该会向您显示一个简单的进度条,它只是一直在转圈。如果没有,那就是其他地方有问题了。

之后,您可以通过添加最小值/最大值来进行构建,以查看它是否变直

最后,添加可绘制对象,我只是猜测,这可能是这里的问题,我们可以查看失败的确切原因,但随后我们找到了根本原因,可以轻松搜索错误。 :)

编辑:

我在网上看了看,从我发现的内容来看,drawable 看起来应该与此类似(虽然未经测试):How to set color to secondary drawable in progress bar

Android已经内置了循环进度条,试试这个:

<ProgressBar
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:indeterminate="true"
    android:id="@+id/prgrsbar"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

如果太大可以用progressBarStyleSmall代替progressBarStyleLarge,或者自己定制。