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>
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.