Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to make table columns equal to a fraction of the total width?

So far in my learning I have only come across spreading column sizes equally, giving one/two a higher priority to take as much space as they need, or setting the size of a column manually.

I was wondering if there was anyway of setting a column size in Android to be a fraction of the total table size. I want to split it into sixths. 1/6 for the first column, 3/6 for the second column and 2/6 for the third.

Is there any way to do this?

like image 615
NotACleverMan Avatar asked Dec 01 '10 16:12

NotACleverMan


1 Answers

You can do this by using android:layout_span

Here is an 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="*">

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:background="#aa0000"
            android:text="1/6"
            android:gravity="center_horizontal"/>
        <TextView
            android:background="#00aa00"
            android:text="3/6"
            android:gravity="center_horizontal" 
            android:layout_span="3"/>
        <TextView
            android:background="#0000aa"
            android:text="2/6"
            android:gravity="center_horizontal"
            android:layout_span="2"/>
        </TableRow>
</TableLayout>
like image 159
Etienne Avatar answered Sep 19 '22 01:09

Etienne