进度条

时间:2015-07-20 14:20:29

标签: android

我正在尝试做这样的事情:

enter image description here

这就是我的代码所做的:

enter image description here

我的可绘制文件中有这段代码:

progress_bar_layout.xml

<?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:innerRadius="70dp"
            android:shape="ring"
            android:thickness="18dp">
        </shape>
    </item>

<item android:id="@android:id/progress">
    <shape
        android:innerRadius="70dp"
        android:shape="ring"
        android:thickness="18dp">

        <gradient
            android:endColor="#ff0f315f"
            android:startColor="#ff005563"
            android:type="sweep" />
    </shape>
</item>


<item android:id="@android:id/secondaryProgress">
    <shape
        android:innerRadius="70dp"
        android:shape="ring"
        android:thickness="18dp">

        <gradient
            android:endColor="#ff1490e4"
            android:startColor="#ff00c0dd"
            android:type="sweep" />
    </shape>
</item>

</layer-list>

布局:

    <ProgressBar
        android:id="@+id/bar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="180dp"
        android:layout_height="180dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:max="100"
        android:progress="99"
        android:progressDrawable="@drawable/progress_bar_layout"
        android:secondaryProgress="30" />

问题是我的背景风格没有显示出来。这就是为什么我正在使用进度来完成后台的工作,但正如你所看到的,它不能很好地工作,最大尺寸是99,最后还有一个空间。我错过了一些代码吗?

1 个答案:

答案 0 :(得分:3)

基本上,我必须为每个元素拆分 progress_bar_layout.xml 可绘制文件,因此,一个文件包含进度设置,另一个文件包含背景设置。 然后,我将它们添加到各自的元素中。

 android:background="@drawable/circle_shape"
 android:progressDrawable="@drawable/circular_progress_bar" />

使用图层列表,项目没有找到背景设置,所以这种方法解决了我的问题。

<强> circle_shape.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="60dp"
    android:shape="ring"
    android:thickness="10dp"
    android:useLevel="false">

    <solid android:color="@color/blue"></solid>

</shape>

<强> circular_progress_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="270"
    android:toDegrees="270">
    <shape
        android:innerRadius="60dp"
        android:shape="ring"
        android:thickness="10dp"
        android:useLevel="true">

        <solid android:color="@color/blue"></solid>

    </shape>
</rotate>
相关问题