zoukankan      html  css  js  c++  java
  • 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列

  • 相关阅读:
    Shell重新学习(忘光了)
    vim 设置默认显示行号
    maven学习资料(三)
    maven:新建的maven工程需要添加一下插件
    Spring框架:第五章:Spring EL表达式
    Spring框架:第四章:Spring管理数据库连接池
    Spring框架:第三章:对象的生命周期及单例bean生命周期的11个步骤
    Spring框架:第二章:IOC依赖注入及40个实验
    Spring框架:第一章:介绍和准备工作
    MyBatis框架:第十一章:mybatis 逆向工程
  • 原文地址:https://www.cnblogs.com/xs104/p/4725973.html
Copyright © 2011-2022 走看看