Friday, January 16, 2015

How to span columns and rows in a GridLayout in Android

GridLayout Row Span Column Span
activity_main.xml

<GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:columnCount="3"
    android:rowCount="4"
    android:layout_margin="15dp"
    android:background="#DEB887"
    >
    <Button android:text="Button 1" />
    <Button android:text="Button 2" />
    <Button android:text="Button 3" />
    <Button android:text="Button 4" />
    <Button android:text="Column Span 2"
            android:layout_columnSpan="2"
            />
    <Button android:text="Button 6" />
    <Button android:text="Row Span 2"
            android:layout_rowSpan="2"
            />
    <Button android:text="Button 8" />
    <Button android:text="Button 9" />
    <Button android:text="Button 10" />
    <Button android:text="Button 11" />
    <Button android:text="Button 12" />
    <Button android:text="Button 13" />
</GridLayout>
More android examples