0

Given this layout XML snippet:

    <TableLayout
        android:id="@+id/review_ltpv_table"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:stretchColumns="*">

        <!-- TODO: This row's cells don't line up with the rows below. Fix. -->
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/review_text_view_look"
                android:text="@string/review_look"
                android:textAppearance="@style/TextBody" />

            <TextView
                android:id="@+id/review_text_view_taste"
                android:text="@string/review_taste"
                android:textAppearance="@style/TextBody" />

            <TextView
                android:id="@+id/review_text_view_portion"
                android:text="@string/review_portion"
                android:textAppearance="@style/TextBody" />

            <TextView
                android:id="@+id/review_text_view_value"
                android:text="@string/review_value"
                android:textAppearance="@style/TextBody" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="0dp" >

            <ToggleButton
                android:id="@+id/review_look_positive"
                style="@style/ButtonPositive"
                android:onClick="onLookPositive"
                android:textOn="@null"
                android:textOff="@null" />

            <ToggleButton
                android:id="@+id/review_taste_positive"
                style="@style/ButtonPositive"
                android:onClick="onTastePositive"
                android:textOn="@null"
                android:textOff="@null" />

            <ToggleButton
                android:id="@+id/review_portion_positive"
                style="@style/ButtonPositive"
                android:onClick="onPortionPositive"
                android:textOn="@null"
                android:textOff="@null" />

            <ToggleButton
                android:id="@+id/review_value_positive"
                style="@style/ButtonPositive"
                android:onClick="onValuePositive"
                android:textOn="@null"
                android:textOff="@null" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="0dp" >

            <ToggleButton
                android:id="@+id/review_look_negative"
                style="@style/ButtonNegative"
                android:onClick="onLookNegative"
                android:textOn="@null"
                android:textOff="@null" />

            <ToggleButton
                android:id="@+id/review_taste_negative"
                style="@style/ButtonNegative"
                android:onClick="onTasteNegative"
                android:textOn="@null"
                android:textOff="@null" />

            <ToggleButton
                android:id="@+id/review_portion_negative"
                style="@style/ButtonNegative"
                android:onClick="onPortionNegative"
                android:textOn="@null"
                android:textOff="@null" />

            <ToggleButton
                android:id="@+id/review_value_negative"
                style="@style/ButtonNegative"
                android:onClick="onValueNegative"
                android:textOn="@null"
                android:textOff="@null" />
        </TableRow>

    </TableLayout>

I see this:

enter image description here

Why do the vertical borders between the cells in the top row not line up with those in the rows below? This is not a table!

If I remove android:stretchColumns="*" from the layout tag it looks even worse - the cells in the top row just bunch up on the left.

If I add android:layout_weight="1" to the TextViews it makes no difference.

This is API level 22.

Eliot
  • 2,349
  • 3
  • 28
  • 45

1 Answers1

0

I think you do not use the "weight" correctly, I would suggest to try to change your first row to :

    <TableRow
        android:weightSum="4">

        <TextView
            android:id="@+id/review_text_view_look"
            android:text="@string/review_look"
            android:layout_weight="1"
            android:textAppearance="@style/TextBody" />

        <TextView
            android:id="@+id/review_text_view_taste"
            android:text="@string/review_taste"
            android:layout_weight="1"
            android:textAppearance="@style/TextBody" />

        <TextView
            android:id="@+id/review_text_view_portion"
            android:text="@string/review_portion"
            android:layout_weight="1"
            android:textAppearance="@style/TextBody" />

        <TextView
            android:id="@+id/review_text_view_value"
            android:text="@string/review_value"
            android:layout_weight="1"
            android:textAppearance="@style/TextBody" />
    </TableRow>

So every cells have the same weight and will be of the same size

Aznhar
  • 610
  • 1
  • 10
  • 30