I don't know how to change this screen configuration to TableLayout or GridLayout, which was created only with LinearLayout.

Asked 2 years ago, Updated 2 years ago, 50 views

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"></LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"></LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"></LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"></LinearLayout>
    </LinearLayout>

</LinearLayout>

I just created this screen configuration. If you write it like this, it splits into the X and Y axes and comes out with four sections How can I write this in grid layout or table layout?

I think I've tried various methods, but I don't know if there's no weight attribute, so it's going to go off the screen

android layout

2022-09-21 17:59

1 Answers

I think you make everything you want with grid or table I think you can use linearlayout for only 4 parts and use table or grid for the contents.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <TableRow>
                <TextView android:text="Name" />
                <TextView android:text="Name" />
            </TableRow>
        </TableLayout>

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <TableRow>
                <TextView android:text="Name" />
                <TextView android:text="Name" />
                <TextView android:text="Name" />
            </TableRow>

            <TableRow>
                <TextView android:text="Name" />
                <TextView android:text="Name" />
                <TextView android:text="Name" />

            </TableRow>


        </TableLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">
            <TableRow>
                <TextView android:text="Name" />
                <TextView android:text="Name" />
            </TableRow>

        </TableLayout>

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">
            <TableRow>
                <TextView android:text="Name" />
                <TextView android:text="Name" />
            </TableRow>

        </TableLayout>
    </LinearLayout>

</LinearLayout>


2022-09-21 17:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.