2016-08-01 110 views
1

我有一個通過xml設計的圓形進度條。問題是,如果我將layout_width和layout_height設置爲wrap_content,它將切斷圓圈。如果我手動將寬度和高度設置爲「__dp」,那麼圓周邊會有一個巨大的框,它會擴大太多。爲了更清楚地解釋,我的進度條在你觸摸它時開始。但是,即使您觸摸了進度條旁邊的邊框,它也會啓動(當不應該時)。我怎樣才能刪除這個邊界?謝謝!Android,移除圓形進度條周圍的方形邊框

enter image description here

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

circle_shape.xml

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

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

</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:innerRadiusRatio="7" 
     android:shape="ring" 
     android:thickness="5dp" 
     android:useLevel="true"> 

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

回答

1

您設置了錯誤的風格。

style="?android:attr/progressBarStyleHorizontal" 

是指橫向ProgressBar s。刪除樣式或使用一個旨在用於圓形ProgressBar的樣式,如

style="@style/Base.Widget.AppCompat.ProgressBar" 
+0

如果我這樣做,它周圍仍然有一個盒子。 – Jill

+0

你可以發佈你正在使用的兩個drawable嗎 – FWeigl

+0

當然,我把它添加到問題 – Jill