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

表格布局

表格布局就是以行列的形式来管理布局管理器中的组件,使组件以特定的行列排列
表格布局用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

  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的登录/注册界面布局代码,使用Android Studio: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 注册界面 --> <RelativeLayout android:id="@+id/register_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"> <EditText android:id="@+id/register_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="用户名" android:padding="16dp" /> <EditText android:id="@+id/register_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="密码" android:inputType="textPassword" android:padding="16dp" /> <Button android:id="@+id/register_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/register_password" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:text="注册" /> <TextView android:id="@+id/register_login_link" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/register_button" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:text="已有账号?登录" /> </RelativeLayout> <!-- 登录界面 --> <RelativeLayout android:id="@+id/login_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:id="@+id/login_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="用户名" android:padding="16dp" /> <EditText android:id="@+id/login_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="密码" android:inputType="textPassword" android:padding="16dp" /> <Button android:id="@+id/login_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/login_password" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:text="登录" /> <TextView android:id="@+id/login_register_link" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/login_button" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:text="没有账号?去注册" /> </RelativeLayout> </RelativeLayout> ``` 这个布局文件包含两个RelativeLayout,一个是注册界面,一个是登录界面。默认情况下,注册界面是隐藏的,只有当用户点击登录界面的“没有账号?去注册”链接时,注册界面才会显示出来。 在登录界面中,有两个EditText分别用于输入用户名和密码,还有一个登录按钮。在注册界面中,也有两个EditText分别用于输入用户名和密码,还有一个注册按钮。此外,还有两个TextView用于在登录界面和注册界面之间切换。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值