2010-04-29 158 views

回答

24

如果你的進度條在XML佈局定義,它看起來像你定義它的高度,像這樣:

<ProgressBar 
android:minHeight="20dip" 
android:maxHeight="20dip"/> 

但是我只是製作從this article猜測。

+2

API> 11如何將其自動添加到操作欄? – Taranfx 2012-04-03 06:50:37

16

訣竅是讓您的ProgressBar使用「舊」,無暈,風格。否則,它將使用9補丁圖像作爲可繪製的進度,除非您操作圖像,否則無法更改高度。因此,這裏是我做過什麼:

的進度:

<ProgressBar 
    android:id="@+id/my_progressbar" 
    style="@android:style/Widget.ProgressBar.Horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="10dp" 
    android:progressDrawable="@drawable/horizontal_progress_drawable_red" /> 

進度繪製(horizo​​ntal_progress_drawable_red.xml):

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:id="@android:id/background"> 
     <shape> 
      <solid android:color="#808080"/> 
     </shape> 
    </item> 

    <item android:id="@android:id/secondaryProgress"> 
     <clip> 
      <shape> 
       <solid android:color="#80ff0000"/> 
      </shape> 
     </clip> 
    </item> 

    <item android:id="@android:id/progress"> 
     <clip> 
      <shape> 
       <solid android:color="#ff0000"/> 
      </shape> 
     </clip> 
    </item> 

</layer-list> 
+1

可繪製進度應該是什麼根源? 編輯: clocksmith 2014-07-11 18:24:30

16

您需要更換

style=」?android:attr/progressBarStyleHorizontal」 

style="@android:style/Widget.ProgressBar.Horizontal" 

和layout_height將工作

android:layout_height="50dp" 
+0

工作就像一個魅力!謝謝 – 2015-03-11 11:03:41

+1

如何添加顏色等屬性? – 2016-06-30 15:56:07

+0

您可以在SeekBar XML中使用「android:progressTint」和「android:progressBackgroundTint」設置進度和進度背景的顏色。 – Luke 2017-06-12 13:04:27

1

可以使用此代碼:

mProgressBar.setScaleY(3f); 

或者使用自定義樣式

值 - > styles.xml

<style name="tallerBarStyle" parent="@android:style/Widget.SeekBar"> 
    <item name="android:indeterminateOnly">false</item> 
    <item name="android:progressDrawable">@android:drawable/progress_horizontal</item> 
    <item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item> 
    <item name="android:minHeight">8dip</item> 
    <item name="android:maxHeight">20dip</item> 
</style> 

然後在您的ProgressBar添加:

style="@style/tallerBarStyle"