Android studio APP开发 表格布局 用表格布局写一个用户登录界面

本文详细介绍了Android中的表格布局(TableLayout)概念及其使用方法。表格布局通过TableRow元素定义每一行,支持多列显示,适用于创建表格形式的UI界面。文章还解释了TableLayout的常见属性,如collapseColumns、shrinkColumns和stretchColumns,以及如何通过XML代码实现具体的布局效果。

表格布局

表格布局就是以行列的形式来管理布局管理器中的组件,使组件以特定的行列排列
表格布局用TableLayout标记定义,在表格布局中,用TableRow来标记,每个TableRow占用一行

TableLayout支持的属性

属性作用
android:collapseColums设置需要被隐藏的列序号(序号从0开始),多个列序号之间用逗号隔开
android:shrinkColums设置允许被收缩的列的列序号(序号哦才能够0开始),多个列序号之间用逗号隔开
android:stretchColums设置允许被拉伸的序列号(序号从0开始), 多个列序号之间用逗号隔开
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:padding="20dp"
    android:weightSum="15">
    
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:padding="6dp">
        <TextView/>
        <TextView
            android:text="用户名"
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary"
            android:textSize="24sp"/>
        
        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:textSize="24sp"
            android:minWidth="200dp"/>
    </TableRow>
    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:padding="6dp">
        <TextView/>
        <TextView
            android:text="密码"
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary"
            android:textSize="24sp"/>

        <EditText
            android:id="@+id/editText2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:textSize="24sp"
            android:minWidth="200dp"
            android:inputType="textPassword"/>
    </TableRow>
    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:padding="10dp">
        <TextView/>
        <Button
            android:text="登录"
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/colorAccent"
            android:textSize="24sp"/>

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="退出"
            android:background="@color/colorAccent"
            android:textSize="24sp"
            android:minWidth="200dp"/>
    </TableRow>

</TableLayout>

xiaoguotu

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值