开发者

Table with varying column count and auto column widths

I want to draw a table/grid by specifying the column count for each row and draw some cells in different colors. A row should span over the whole screen. The column-widths should be the same for the columns for each row. I tried using TableLayout with View or Textviews, b开发者_StackOverflow中文版ut I couldn't figure out how I can distribute the columns evenly for each row.

The grid should look something like this: http://img148.imageshack.us/img148/4239/gridk.png


I don't know that a TableLayout is really what you are looking for, since the columns in your different rows don't line up.

In general, if you want to add a bunch of Views to a row and have them each take up the same amount of space, you can set the android:layout_weight = 1 on each of the views.

For example, for a single row:

<LinearLayout android:layout_width="FILL_PARENT" android:layout_height="WRAP_CONTENT" android:orientation="horizontal">
   <TextView android:layout_weight="1"/>
   <TextView android:layout_weight="1"/>
   <TextView android:layout_weight="1"/>
   <TextView android:layout_weight="1"/>
</LinearLayout>

For the multiple rows, you could use a LinearLayout with android:orientation="vertical", or a TableLayout you could have only one column in your TableRow.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜