Android:如何更改进度条的高度?

发布于 2024-08-30 23:32:19 字数 73 浏览 2 评论 0原文

我想知道在 Android 中更改 ProgressBar 高度的最简单方法是什么?

谢谢,

托梅克

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

Thanks,

Tomek

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深居我梦 2024-09-06 23:32:19

如果您的进度条是在 XML 布局中定义的,那么您似乎是这样定义其高度的:

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

但是我只是从 本文

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.

挖鼻大婶 2024-09-06 23:32:19

您需要替换

style=”?android:attr/progressBarStyleHorizontal”

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

,layout_height 才能工作

android:layout_height="50dp"

You need to replace

style=”?android:attr/progressBarStyleHorizontal”

to

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

and layout_height will work

android:layout_height="50dp"
对风讲故事 2024-09-06 23:32:19

诀窍是让你的进度条使用“旧的”、无光环的样式。否则,它将使用 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>

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>
泪意 2024-09-06 23:32:19

可以使用这段代码:

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"

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文