23

Am learning android and am struggling to get my head around this particular layout attribute, reading the google dev docs it says:

android:layout_column

The index of the column in which this child should be. Must be an integer value, such as "100". This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type. This corresponds to the global attribute resource symbol layout_column.

Can anyone explain how this maps to an html equivalent (as table rows appear to borrow heavily from them)?

Is it the number of columns it take sup - eg colspan?

Kushal
  • 8,100
  • 9
  • 63
  • 82
Alphatester77
  • 702
  • 3
  • 8
  • 16

1 Answers1

30

Uh, it means "the index of the column in which this child should be". The only tricky part is that columns start at 0.

For example:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">
    <TableRow>
        <TextView
                android:text="URL:" />
        <EditText android:id="@+id/entry"
            android:layout_span="3"/>
    </TableRow>
    <TableRow>
        <Button android:id="@+id/cancel"
            android:layout_column="2"
            android:text="Cancel" />
        <Button android:id="@+id/ok"
            android:text="OK" />
    </TableRow>
</TableLayout>

Both rows in the above layout have four columns. The first one has four columns because it has a TextView in column 0 and an EditText spanning columns 1, 2, and 3. The second one has four columns because it skips columns 0 and 1 and puts the two Button widgets in columns 2 and 3, courtesy of the android:layout_column="2" attribute in the first Button.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    Ah right that makes sense then - didn't follow as html doesn't work in this manner with index-based tables, it 'assumes' the width with each by default. – Alphatester77 Dec 04 '10 at 23:33
  • 8
    @Alphatester77: Yes, while `TableLayout` shares many commonalities with HTML tables, this is not one of them. Think of `android:layout_column` as shorthand for "slap some empty `` tags to the left of me to take up some columns". – CommonsWare Dec 04 '10 at 23:36
  • Cool, that makes sense now - thanks for the extra explanation, helps a lot! – Alphatester77 Dec 04 '10 at 23:41