2016-01-29 35 views
0

我有自定義的進度條形狀......並且我想要使背景(用灰色填充)使撫摸,iner和外部撫摸與他們之間的9dp間隔... 似乎我可以不能讓它工作。寬度的撫摸戒指形狀

這是進度條內圈的原始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:innerRadius="60dp" 
      android:shape="ring" 
      android:thickness="9dp" 
      android:useLevel="true"> 


     <gradient 
      android:startColor="@color/light_gray" 
      android:endColor="@color/light_gray" 
      android:type="sweep" /> 

     </shape> 

    </item> 
</layer-list> 

這是輸出截圖: Progress Bar

而一個問題更(我不想打開另一個問題): - 能我做這個橙色的結束是橢圓形(四捨五入)不知何故?像大多數進度條一樣? XML與上面的一樣,只是顏色不同而已。

編輯:這可能有幫助,我使用具有自定義背景的進度條組件。

EDIT2:我通過設置圓半徑60和厚度1dp,並創建另一個具有69半徑和1dp厚度的背景的ProgressBar組件來完成。

我得到了我需要的設計,這不是好的方法。我可以在第二個問題上得到幫助嗎?

+0

爲你的第二個問題改變android:shape =「oval」 – Madhur

+0

@Madhur,「橢圓形」是不正確的答案。因爲我需要戒指形狀。 :/ – Sasaman

回答

0

請參考下面的代碼來創建進度條

<?xml version="1.0" encoding="utf-8"?> 
<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" 
    android:toDegrees="360"> 
    <shape android:shape="ring" android:innerRadiusRatio="3" 
     android:thicknessRatio="8" android:useLevel="false"> 

     <size android:width="76dip" android:height="76dip" /> 
     <gradient android:type="sweep" android:useLevel="false" 
      android:startColor="@android:color/transparent" 
      android:endColor="#00FF00" 
      android:angle="0" 
      /> 
    </shape> 
</rotate> 

和有外觀和感覺,並獲得更多信息,請參閱https://pankajchunchun.wordpress.com/2011/09/10/customization-of-spinner-progress/

+0

它對你有用嗎? –

+0

謝謝你的回答 - 但不要,因爲我已經有了這個曲線文本和一些東西的進度條。我需要這種類型,因爲它一個接一個地滴答60秒。只是想在其中有撫摸的路徑。 :/ – Sasaman

0

我認爲最好的方法是使用一個自定義視圖。通過這種方法可以得出一個環帶圓帽:

int border = 4; // This value is in PX! 
RectF rect = new RectF(); 
Paint paint = new Paint(); 
int radius = getMeasuredWidth() - border/2; 

rect.set(border/2, border/2, radius, radius); 
paint.setStrokeWidth(border); 
paint.setAntiAlias(true); 
paint.setStrokeCap(Paint.Cap.ROUND); 
paint.setStyle(Paint.Style.STROKE); 
paint.setColor(Color.Orange); 
canvas.drawArc(rect, -90, 360, true, paint); 

然後你可以畫內的另一個圈或其它圈爲背景。希望能幫助到你!

+0

謝謝,我可以用形狀做它,因爲不知道如何用這樣的畫布做到這一點。因爲我有自定義背景的進度條組件。 :) – Sasaman