如何顺时针方向进行循环倒计时?

时间:2016-09-27 09:29:25

标签: android android-progressbar

我有一个倒计时的循环进度条。倒计时从圆形进度条的顶部开始,这是正常的,但在倒计时时向左移动。我想要的是倒计时的旋转向右移动,就像顺时针一样。

我的circle_progress_foreground.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/progress">
        <shape
            android:innerRadiusRatio="3"
            android:shape="ring"
            android:thicknessRatio="30"
            android:useLevel="true">

            <gradient
                android:startColor="@color/circle_progress_two"
                android:endColor="@color/circle_progress"
                android:type="sweep" />
        </shape>
    </item>
</layer-list>

布局中的进度条

<ProgressBar
            android:id="@+id/progressbar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="280dip"
            android:layout_height="290dip"
            android:indeterminate="false"
            android:progressDrawable="@drawable/circle_progress_foreground"
            android:background="@drawable/circle_shape"
            android:max="100"
            android:rotation="-90"
            android:layout_alignParentTop="true"
            android:layout_alignLeft="@+id/progressBar"
            android:layout_alignStart="@+id/progressBar"
            android:layout_centerHorizontal="false"
            android:layout_centerInParent="false"
            android:layout_centerVertical="false" />

我班上的代码:

mProgressBar = (ProgressBar) findViewById(R.id.progressbar);

1 个答案:

答案 0 :(得分:1)

尝试这种方式来设置你的轮换

circle_progress_foreground.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:innerRadiusRatio="2.5"
        android:shape="ring"
        android:thickness="1dp"
        android:useLevel="true">

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

circle_shape

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:innerRadiusRatio="2.5"
    android:thickness="1dp"
    android:useLevel="false">

    <solid android:color="#CCC" />

</shape>

进度

<ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:indeterminate="false"
        android:progressDrawable="@drawable/circle_progress_foreground"
        android:background="@drawable/circle_shape"
        style="?android:attr/progressBarStyleHorizontal"
        android:max="100"
        android:progress="65" />