Android实战技巧之三十四 用TableLayout伪装表格显示数据

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                       

先来上个图,最终效果图。

每个Layout都有自己最适用的场景,而TableLayout往往用在中规中矩的输入界面,比如下图:

TableLayout下嵌套TableRow组成Table的行;每个TableRow中布局不同的控件,组成Table的列。上图就是两列四行,而我们要做的表格就是三行三列。

TableLayout是没有提供边框的,要作成表格的效果需要我们使用一些技巧:
整个TableLayout的背景色设成黑色,而每个Table的cell(其实就是每个控件)的背景色设成白色,然后cell的边距根据情况设置一个px,就可以了。
布局代码如下:

    <TableLayout        android:id="@+id/table"        android:layout_below="@id/spinner"        android:layout_width="wrap_content"        android:background="@color/black"        android:layout_height="wrap_content">        <TableRow            android:layout_marginTop="1dp"            android:layout_marginRight="1dp"            android:layout_marginLeft="1dp"            android:layout_width="wrap_content"            android:layout_height="wrap_content">            <TextView android:text="姓名"                android:textSize="@dimen/table_text_size"                android:background="@color/white"                android:layout_width="@dimen/table_item1_width"                android:layout_height="wrap_content" />            <TextView android:text="学校"                android:textSize="@dimen/table_text_size"                android:background="@color/white"                android:layout_marginLeft="1dp"                android:layout_width="@dimen/table_item2_width"                android:layout_height="wrap_content" />            <TextView android:text="专业"                android:textSize="@dimen/table_text_size"                android:background="@color/white"                android:layout_marginLeft="1dp"                android:layout_width="@dimen/table_item3_width"                android:layout_height="wrap_content" />        </TableRow>        <TableRow            android:layout_marginTop="1dp"            android:layout_marginBottom="1dp"            android:layout_marginRight="1dp"            android:layout_marginLeft="1dp"            android:layout_width="wrap_content"            android:layout_height="wrap_content">            <TextView android:text="张飞"                android:textSize="@dimen/table_text_size"                android:background="@color/white"                android:layout_width="@dimen/table_item1_width"                android:layout_height="wrap_content" />            <TextView android:text="野鸡大学"                android:textSize="@dimen/table_text_size"                android:background="@color/white"                android:layout_marginLeft="1dp"                android:layout_width="@dimen/table_item2_width"                android:layout_height="wrap_content" />            <TextView android:text="体育系"                android:textSize="@dimen/table_text_size"                android:background="@color/white"                android:layout_marginLeft="1dp"                android:layout_width="@dimen/table_item3_width"                android:layout_height="wrap_content" />        </TableRow>        <TableRow            android:layout_marginBottom="1dp"            android:layout_marginRight="1dp"            android:layout_marginLeft="1dp"            android:layout_width="wrap_content"            android:layout_height="wrap_content">            <TextView android:text="刘备"                android:textSize="@dimen/table_text_size"                android:background="@color/white"                android:layout_width="@dimen/table_item1_width"                android:layout_height="wrap_content" />            <TextView android:text="皇家学院"                android:textSize="@dimen/table_text_size"                android:background="@color/white"                android:layout_marginLeft="1dp"                android:layout_width="@dimen/table_item2_width"                android:layout_height="wrap_content" />            <TextView android:text="经济"                android:textSize="@dimen/table_text_size"                android:background="@color/white"                android:layout_marginLeft="1dp"                android:layout_width="@dimen/table_item3_width"                android:layout_height="wrap_content" />        </TableRow>    </TableLayout>
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值