Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Grid Layout 2x2 attempt equal sized, screen-filling attempt
<?xml version="1.0" encoding="utf-8"?>
<!-- REMEMBER TO UPDATE BOTH LANDSCAPE AND PORTRAIT FILES -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:grid="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Setting up GridLayout support library in IntelliJ: http://stackoverflow.com/questions/12468606/intellij-and-android-support-v7-widget-gridlayout -->
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
grid:columnCount="2"
grid:rowCount="2"
android:background="#FFF">
<LinearLayout
android:id="@+id/redSquare"
android:layout_columnSpan="1"
android:layout_rowSpan="1"
android:background="#F00"
grid:layout_row="0"
grid:layout_column="0"
android:layout_width="50dp"
android:layout_height="50dp"
/>
<LinearLayout
android:id="@+id/greenSquare"
android:layout_columnSpan="1"
android:layout_rowSpan="1"
android:background="#0F0"
grid:layout_row="0"
grid:layout_column="1"
android:layout_width="50dp"
android:layout_height="50dp"
/>
<LinearLayout
android:id="@+id/blueSquare"
android:layout_columnSpan="1"
android:layout_rowSpan="1"
android:background="#00F"
grid:layout_row="1"
grid:layout_column="0"
android:layout_width="50dp"
android:layout_height="50dp"
/>
</android.support.v7.widget.GridLayout>
</LinearLayout>
@Heisarki

This comment has been minimized.

Copy link

@Heisarki Heisarki commented Nov 16, 2020

*********** make the GridLayout height and width as match_parent
***********and all the children layout height and width as wrap_content

<androidx.gridlayout.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:columnCount="2">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">>

                <Button
                    android:id="@+id/button16"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Button" />
            </LinearLayout>
            />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">>

                <Button
                    android:id="@+id/button17"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Button" />
            </LinearLayout>
            />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">>

                <Button
                    android:id="@+id/button18"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Button" />
            </LinearLayout>
            />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">>

                <Button
                    android:id="@+id/button19"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Button" />
            </LinearLayout>
            />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">>

                <Button
                    android:id="@+id/button20"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Button" />
            </LinearLayout>
            />

        </androidx.gridlayout.widget.GridLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment