Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Layout: Why don't the TextView and a ToggleButton align

I'm trying to put a TextView and a ToggleButton in a table row, however, they don't seem to align (The top of the button starts about 10px below the top of the textview even though the height each element is the same. Can anyone tell me why?

<TableLayout
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"

        >
    <TableRow>
        <AutoCompleteTextView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:layout_weight="1"
        />

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

        </TableLayout>
like image 413
Ally Avatar asked Jun 27 '26 03:06

Ally


1 Answers

TableRow behaves like LinearLayout and tries to align widgets with text along their baseline by default. Set android:layout_gravity="center_vertical" (or any other gravity setting) on your ToggleButton if you'd like it to align differently.

like image 194
adamp Avatar answered Jun 29 '26 21:06

adamp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!