↓ I want to expand this button to the full width.
Original code
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button" />
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent">
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button" />
</TableRow>
</TableLayout>
stretchColumns android: stretchColumns = "column number" is set.
activity_main.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1">
It spread beautifully.
This time when the button extends beyond the width of the screen.
shrinkColumns android: shrinkColumns = "Column number" is set.
activity_main.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="0,1,2,3,4">
It fits.
Set the table row to weight = "1".
activity_main.xml
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
Set shrinkColumns and weight = "1".
activity_main.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="0,1,3,4">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
Recommended Posts