Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Nilzor
Created January 25, 2013 10:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Nilzor/4633342 to your computer and use it in GitHub Desktop.
Save Nilzor/4633342 to your computer and use it in GitHub Desktop.
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
Copy link

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