I want the buttons to be their original size (wrap content), but them to be aligned in that logical cell location. Is that possible? I mean, I want something like,
|[Lisa]_______|[Simpson]____|
not,
|[___Lisa____]|[__Simpson__]|
or,
|[Lisa]|[Simpson]___________|
The following code did not work.
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Lisa"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Simpson"/>
</TableRow>
TableLayout
centers its items by default. What you can use is a LinearLayout
, like this:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Lisa"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Simpson"/>
</LinearLayout>
This divides the space of the two buttons evenly, but does not center each button. This is how it looks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.