Wednesday, February 6, 2013

GridLayout

android.widget.GridLayout added in API level 14, is a layout that places its children in a rectangular grid.

Example:

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="3"
    tools:context=".MainActivity" >

    <TextView
        android:textSize="28sp"
        android:text="@string/hello_world" />
    <TextView
        android:textSize="28sp"
        android:background="#D0D0D0"
        android:text="Cell 2" />
    <TextView
        android:textSize="28sp"
        android:background="#B0B0B0"
        android:layout_rowSpan="2"
        android:text="Double Row Cell 3" />
    <TextView
        android:textSize="28sp"
        android:background="#909090"
        android:layout_columnSpan="2"
        android:text="Double Column Cell 4" />
    <TextView
        android:textSize="28sp"
        android:background="#505050"
        android:text="Cell 7" />
    <TextView
        android:textSize="28sp"
        android:background="#FF0000"
        android:text="Cell 8" />
    <TextView
        android:textSize="28sp"
        android:background="#00FF00"
        android:text="Cell 9" />
    <TextView
        android:textSize="28sp"
        android:background="#0000FF"
        android:layout_columnSpan="2"
        android:text="Double Column Cell 10" />
    <TextView
        android:textSize="28sp"
        android:background="#E0E0E0"
        android:text="Cell 12" />
</GridLayout>


GridLayout example

No comments:

Post a Comment