Android笔记(十) Android中的布局——表格布局

         TableLayout运行我们使用表格的方式来排列控件,它的本质依然是线性布局。表格布局采用行、列的形式来管理控件,TableLayout并不需要明确的声明包含多少行多少列,而是通过添加TableRow、其他组件来控制表格的行数和列数。

         每次向Table中添加一个TableRow,该TableRow就是一个表格行,TableRow也是容器,因此它也可以不断的添加其他组件,每添加一个子组件该表格就增加一列。

         实例代码,实现一下简单的登录界面

         tablelayout.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1">

    <TableRow>
        <TextView android:layout_height="wrap_content"
            android:text="账户:"/>
        <EditText
            android:id="@+id/usernameInput"
            android:layout_height="wrap_content"
            android:hint="输入要注册的用户名"/>
    </TableRow>

    <TableRow>
        <TextView android:layout_height="wrap_content"
            android:text="密码:"/>
        <EditText
            android:id="@+id/passwordInput"
            android:layout_height="wrap_content"
            android:hint="输入要密码"/>
    </TableRow>

    <TableRow>
        <Button
            android:id="@+id/loginButton"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="登录"/>
    </TableRow>
</TableLayout>

  显示结果为:

  

         显然,太丑了,我们想要在左右两边都有一定的间距,并且所有组件都位于屏幕中间,这里就需要一些属性来配合达到这些效果。

         android:collapseColumns="0"——隐藏第0列

         android:shrinkColumns="0"——收缩第0列

         android:stretchColumns="0"——拉伸第0列

转载于:https://www.cnblogs.com/xs104/p/4725973.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值