0

I'm trying to get an Android ProgressBar to horizontally fill the remaining space in a TableLayout. Its parent row seems to occupy the full width, but when I set the layout parameters to match_parent nothing happens. All I get is the same default-sized (48dip wide) ProgressBar.

I found if I just put a ProgressBar inside a LinearLayout and set it to match_parent, I got exactly what I wanted. But somehow it doesn't work properly in a TableLayout?

Here's the relevant layout code:

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="X" />

            <ProgressBar
                android:id="@+id/gyroConfX"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:indeterminate="false" />
        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Y" />

            <ProgressBar
                android:id="@+id/gyroConfY"
                style="?android:attr/progressBarStyleHorizontal"
                android:indeterminate="false" />
        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Z" />

            <ProgressBar
                android:id="@+id/gyroConfZ"
                style="?android:attr/progressBarStyleHorizontal"
                android:indeterminate="false" />
        </TableRow>
    </TableLayout>

And here's what it looks like:

enter image description here

aardvarkk
  • 14,955
  • 7
  • 67
  • 96
  • try using "fill_parent" instead of "match_parent". Also, you can add this in your progress bar: android:layout_width="fill_parent" android:layout_height="wrap_content" – SolArabehety Jan 17 '14 at 18:52

1 Answers1

1

Try adding layout_weight="1" and layout_width="0dp" to the progress bars, like this:

<TableLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Abcdefg"
            />
        <ProgressBar
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            style="?android:attr/progressBarStyleHorizontal"
            />
    </TableRow>
    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Lorem Ipsum"
            />
        <ProgressBar
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            style="?android:attr/progressBarStyleHorizontal"
            />
    </TableRow>
</TableLayout>
Curtis Shipley
  • 7,990
  • 1
  • 19
  • 28