What exactly does android:layout_column do?-ThrowExceptions

Exception or error:

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?

How to solve:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *