【发布时间】:2011-02-13 21:57:36
【问题描述】:
我想知道在 Android 中更改 ProgressBar 高度的最简单方法是什么?
谢谢,
托梅克
【问题讨论】:
标签: java android user-interface layout progress-bar
我想知道在 Android 中更改 ProgressBar 高度的最简单方法是什么?
谢谢,
托梅克
【问题讨论】:
标签: java android user-interface layout progress-bar
如果你的进度条是在 XML 布局中定义的,看起来你是这样定义它的高度的:
<ProgressBar
android:minHeight="20dip"
android:maxHeight="20dip"/>
不过,我只是根据this article 进行猜测。
【讨论】:
你需要更换
style=”?android:attr/progressBarStyleHorizontal”
到
style="@android:style/Widget.ProgressBar.Horizontal"
layout_height 会起作用
android:layout_height="50dp"
【讨论】:
诀窍是让您的 ProgressBar 使用“旧”、无光环样式。否则它将使用 9-patch 图像作为进度可绘制对象,除非您操作图像,否则您无法更改高度。所以这就是我所做的:
进度条:
<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" />
进度可绘制(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>
【讨论】:
可以使用这个代码:
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"
【讨论】: