开发者

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 acr开发者_JAVA技巧oss 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?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜