2016-05-13 61 views
1

這是我style_circular_fill.xml文件爲什麼循環progressBar背景不顯示?

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<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="14.0" 
      android:useLevel="true"> 
      <gradient 
       android:centerColor="#A9E2F3" 
       android:endColor="#A9E2F3" 
       android:startColor="#A9E2F3" 
       android:type="sweep" /> 
     </shape> 
    </rotate> 
</item> 

<item android:id="@android:id/background"> 
    <shape 
     android:innerRadiusRatio="3" 
     android:shape="ring" 
     android:thicknessRatio="14.0" 
     android:useLevel="false"> 

     <gradient 
      android:centerColor="#FFF" 
      android:endColor="#FFF" 
      android:startColor="#FFF" 
      android:type="sweep" /> 

    </shape> 
</item> 

這裏是我的activity.xml文件

<ProgressBar 
    android:id="@+id/progressBar1" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="300dp" 
    android:layout_height="300dp" 
    android:indeterminate="false" 
    android:progressDrawable="@drawable/style_circular_fill" 
    android:max="100" 
    android:progress="10" /> 

而且這裏的進度是結果:

enter image description here

我不知道w hy白色圓圈背景沒有顯示出來...... 有沒有什麼我在.xml文件中做錯了?

+1

可以設置背景顏色是透明的,一些實施例[這裏](http://stackoverflow.com/問題/ 23869248 /改變,半透明背景顏色的 - 進度,機器人) – iestync

回答

0

您可以使用this庫作爲您的材料設計進度條。

如:

<me.zhanghai.android.materialprogressbar.MaterialProgressBar 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:indeterminate="true" 
app:mpb_progressStyle="horizontal" 
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal" /> 
0

我有你的選擇分爲2個不同的可繪製並設置一個背景和另一個用於progressDrawable,似乎很好地工作。

<ProgressBar 
    android:id="@+id/progressBar1" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="300dp" 
    android:layout_height="300dp" 
    android:indeterminate="false" 
    android:progressDrawable="@drawable/style_circular_fill" 
    android:background="@drawable/background_circular" 
    android:max="100" 
    android:progress="20" /> 

在style_circular_fill:

<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="270" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:toDegrees="270" > 
    <shape 
     android:innerRadiusRatio="3" 
     android:shape="ring" 
     android:thicknessRatio="14.0" 
     android:useLevel="true"> 
     <gradient 
      android:centerColor="#A9E2F3" 
      android:endColor="#A9E2F3" 
      android:startColor="#A9E2F3" 
      android:type="sweep" /> 
    </shape> 
</rotate> 

在background_circular:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:innerRadiusRatio="3" 
    android:shape="ring" 
    android:thicknessRatio="14.0" 
    android:useLevel="false"> 

    <gradient 
     android:centerColor="#FFF" 
     android:endColor="#FFF" 
     android:startColor="#FFF" 
     android:type="sweep" /> 

</shape> 
+0

對我來說已經不顯示任何東西 – user3442437