↓ Je souhaite agrandir ce bouton sur toute sa largeur.

Code d'origine
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 = "Numéro de colonne" est défini.
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">
Il s'est magnifiquement répandu.
Cette fois, lorsque le bouton dépasse la largeur de l'écran.

shrinkColumns android: shrinkColumns = "Numéro de colonne" est défini.
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">
Ça rentre.
Définissez le poids = "1" dans TableRow.
activity_main.xml
<TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

Définissez shrinkColumns et 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