Android: How do I change the height of a ProgressBar?

后端 未结 4 1815
滥情空心
滥情空心 2020-12-30 03:45

I was wondering what is the easiest way to change the height of a ProgressBar in Android?

Thanks,

Tomek

相关标签:
4条回答
  • 2020-12-30 04:19

    Can use this code :

    mProgressBar.setScaleY(3f);
    

    Or use custom style

    values->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>
    

    Then in your ProgressBar add:

    style="@style/tallerBarStyle"
    
    0 讨论(0)
  • 2020-12-30 04:26

    The trick is to have your ProgressBar use the "old", none halo, style. Otherwise it will use a 9-patch image as a progress drawable and you can't change the height unless you manipulate the image. So here is what I did :

    the progressbar :

    <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" />
    

    the progress drawable (horizontal_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>
    
    0 讨论(0)
  • 2020-12-30 04:31

    If your progress bar is defined in the XML layout, it looks like you define its height like so:

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

    However I'm just making a guess from this article.

    0 讨论(0)
  • 2020-12-30 04:36

    You need to replace

    style=”?android:attr/progressBarStyleHorizontal”
    

    to

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

    and layout_height will work

    android:layout_height="50dp"
    
    0 讨论(0)
提交回复
热议问题