开发者

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

开发者 https://www.devze.com 2022-12-29 03:50 出处:网络
I was wonderin开发者_高级运维g what is the easiest way to change the height of a ProgressBar in Android?

I was wonderin开发者_高级运维g what is the easiest way to change the height of a ProgressBar in Android?

Thanks,

Tomek


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.


You need to replace

style=”?android:attr/progressBarStyleHorizontal”

to

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

and layout_height will work

android:layout_height="50dp"


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>


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

精彩评论

暂无评论...
验证码 换一张
取 消