android循环进度背景

时间:2017-12-26 10:47:33

标签: android android-progressbar

我想创建一个循环进度条,因为我创建了一个drawable,但是我无法为无法进行的部分集成背景颜色。

这是可绘制的代码:

<?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  xmlns:android="http://schemas.android.com/apk/res/android"
            android:innerRadiusRatio="3"
            android:shape="ring"
            android:thickness="8dp"
            android:useLevel="true">
            <solid android:color="@color/second_grey"/>
        </shape>
    </item>
    <item  android:id="@android:id/progress">
        <clip>
            <shape
                android:innerRadiusRatio="3"
                android:shape="ring"
                android:thickness="8dp"
                android:useLevel="true">
                <gradient android:type="sweep"
                    android:useLevel="false"
                    android:startColor="@color/blue"
                    android:centerColor="@color/green"
                    android:endColor="@color/magenta"
                    android:angle="0"/>
            </shape>
        </clip>
    </item>
</layer-list>

背景视图无法正常显示。

2 个答案:

答案 0 :(得分:1)

试试这个

<?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="3"
            android:shape="ring"
            android:thicknessRatio="20.0"
            android:useLevel="false">
            <solid android:color="@color/colorLightOrange" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <rotate
            android:fromDegrees="270"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toDegrees="270">
            <shape
                android:innerRadiusRatio="3"
                android:shape="ring"
                android:thicknessRatio="20.0"
                android:useLevel="true">
                <solid android:color="@color/colorOrange" />
            </shape>
        </rotate>
    </item>

</layer-list>

<强> XML

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">


        <ProgressBar
            android:id="@+id/cmll_progrssbar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:indeterminate="false"
            android:layoutDirection="rtl"
            android:max="100"
            android:progress="100"
            android:progressDrawable="@drawable/circle_progressbar" />

        <TextView
            android:id="@+id/cmll_completed_per"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/cmll_progrssbar"
            android:layout_alignLeft="@id/cmll_progrssbar"
            android:layout_alignRight="@id/cmll_progrssbar"
            android:layout_alignTop="@id/cmll_progrssbar"
            android:layout_gravity="center"
            android:gravity="center"
            android:padding="10dp"
            android:text="100%" />

    </RelativeLayout>

答案 1 :(得分:1)

将第一个形状的android:useLevel更改为false

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:innerRadiusRatio="3"
            android:shape="ring"
            android:thickness="8dp"
            android:useLevel="false">
            <solid android:color="@color/second_grey" />
        </shape>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape
                android:innerRadiusRatio="3"
                android:shape="ring"
                android:thickness="8dp"
                android:useLevel="true">
                <gradient
                    android:angle="0"
                    android:centerColor="@color/green"
                    android:endColor="@color/magenta"
                    android:startColor="@color/blue"
                    android:type="sweep"
                    android:useLevel="false" />

            </shape>
        </clip>
    </item>
</layer-list>