Wednesday, February 6, 2013

android.widget.Space

android.widget.Space added in API level 14, is a lightweight View subclass that may be used to create gaps between components in general purpose layouts.

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" />
    <Space
        android:layout_columnSpan="2" />
    <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>


Space in GridLayout

1 comment: