2016-09-27 38 views
0

我有一個倒計時的循環進度條。倒計時從循環進度條的頂部開始,沒有問題,但是在倒計時前往左邊。我想要的是倒計時的旋轉向右移動,就像順時針旋轉一樣。我怎樣才能做到圓形倒計時順時針?

我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

試試這個辦法來設置旋轉

c ircle_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" /> 
+0

還在做着旋轉相反的方式順時針方向。我想要以與順時針方向相同的方式旋轉 –

+0

我想知道什麼? –

+0

嗨。如果使用你的代碼,但是開始做倒計時不是按順時針方向進行。正在從右側向左旋轉,我希望以與順時針相同的方式從右向左旋轉。現在我得到相反的輪換。 –