水平ProgressBar显示不正确

时间:2012-06-27 00:38:40

标签: android progress-bar

我创建了一个包含水平ProgressBar的XML文件,但它显示如下图所示:

Progress bar image

这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />


    <ProgressBar
        android:id="@+id/progress"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:max="100"
        android:progress="50" />

</LinearLayout>

发生了什么事?我该如何解决?

4 个答案:

答案 0 :(得分:1)

通常你应该在你的布局中获得一个horizo​​ntalProgress栏,但是尝试

将ProgressBar小部件中的样式标记更改为此

style="?android:attr/progressBarStyleHorizontal"


<ProgressBar
    android:id="@+id/progress"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:max="100"
    android:progress="50" />

答案 1 :(得分:0)

它被扭曲到你给它的大小

android:layout_width="fill_parent"
android:layout_height="fill_parent"

尝试使用wrap_content或设置layout_weight。此外,您似乎对XML布局没有很好的理解。我建议仔细阅读这篇文章:http://developer.android.com/guide/topics/ui/declaring-layout.html

答案 2 :(得分:0)

我建议将其添加到活动文件

pbSurvey.getProgressDrawable().setColorFilter(Color.parseColor("#0668A1"), PorterDuff.Mode.SRC_IN);

答案 3 :(得分:-1)

您是否尝试在XML文件中添加android:indeterminate =“false”?您的进度条XML应如下所示:

<ProgressBar
    android:id="@+id/progress"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:max="100"
    android:indeterminate="false"
    android:progress="50" />

当总进度未知时(即您只是让用户知道他们需要等待,但您不确定需要多长时间),旋转轮用于“不确定”模式。

相关问题