[JAVA] Fill the screen with buttons in TableLayout

I want to widen the width to fill the screen

↓ I want to expand this button to the full width. table1.PNG

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

table6.PNG It spread beautifully.

I want to fit the width in the screen

This time when the button extends beyond the width of the screen.

table2.PNG

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

table3.PNG It fits.

I want to expand the vertical width to fill the screen

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

table4.PNG

I want to fill the screen vertically and horizontally

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

table5.PNG

Recommended Posts

Fill the screen with buttons in TableLayout
Display the list in setDetails on the screen with spring-security
Draw screen with Thymeleaf in SpringBoot
Place in the middle with css
Use JDBC Manager with the settings in jdbc.dicon.
Implement the Like feature in Ajax with Rails.
How to change the action with multiple submit buttons
Organized how to interact with the JDK in stages
[Java] Get the file path in the folder with List
Implemented pull-down in the original app with Active Hash
Switch the display screen when hovering the tab with jQuery
Memo that transitions to the login screen if you are not logged in with devise
In Redmine you can get the project with Project.find (<identifier>)
If it doesn't change with the disable_with option in Safari
I want to transition to the same screen in the saved state
Use your own classes in the lib directory with Rails6
Find the number of days in a month with Kotlin