Android Development

Rapid android development from Berlin

Browsing Posts tagged TableLayout

As the developer guide says that table border lines are not displayed there is only a dirty fix for this problem:

Give the TableLayout a background color, give the TableRow another background color and set margin to the TableRow. The amount of the margin is the amount of the “border”. Same for each View in the TableRow.

A “dirty” sample:

1
2
3
4
5
6
7
8
<TableLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stretchColumns="*" android:background="#ff0000">
    <TableRow android:background="#00ff00" android:layout_margin="2dip">
        <Button android:id="@+id/button" android:text="+" android:background="#0000ff" android:layout_margin="2dip"/>
        <TextView android:text="@string/label"  android:background="#0000ff" android:layout_margin="2dip"/>
        <TextView android:id="@+id/amount"  android:background="#0000ff" android:layout_margin="2dip"/>
    </TableRow>

Source: My answer on anddev.org forum

  • Share/Bookmark

While working on a little game to learn more about Intents, Activity life cycle and other stuff, I used the TableLayout for the first time. I realized that the auto-completion missed the attribute android:layout_span which is referred by the R.attr. The same with android:stretchColumns. As I read some minutes ago, some people still think column span is not possible – so I decided to publish a sample to prove them wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!-- snipped -->
<TableLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stretchColumns="*">
    <TableRow>
        <TextView android:id="@+id/info"
            android:layout_span="3"
	    android:text="@string/info"
	    android:layout_gravity="center_horizontal" />
	</TableRow>
    <TableRow>
	    <Button android:id="@+id/button_add" android:text="+" />
	    <TextView android:text="@string/label" />
	    <TextView android:id="@+id/amount" />
    </TableRow>
<!-- snipped -->
</TableLayout>
<!-- snipped -->

If the auto-completion leaves out an attribute, there can be more attributes being unsupported, so always use the API as cross reference!

  • Share/Bookmark
Powered by WordPress Web Design by SRS Solutions © 2010 Android Development Design by SRS Solutions