首页 > 其他分享 >表格布局管理器

表格布局管理器

时间:2022-10-19 20:25:08浏览次数:62  
标签:管理器 表格 布局 第二列 android tools

表格布局管理器

每一个控件都是表格的一个格子,靠操纵这么个格子来管理布局。

改成布局管理器

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
<TableRow>
    <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮1"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮2"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮3"/>
</TableRow>
    <TableRow>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮4"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮5"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮6"/>
    </TableRow>
</TableLayout>
collapse

隐藏第二列,这样:

    android:collapseColumns="1"		//必须放在tools这一行的前面
    tools:context=".MainActivity">

让第二列允许拉伸,使得整行被占满

android:stretchColumns="1"

允许收缩

android:shrinkColumns="1"

实现 用户登录页面。

一共四行四列

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

    tools:context=".MainActivity">

    <TableRow
        android:paddingTop="200dp">     //设定整个表格的上边距,注意这里是写在尖括号里面的
        <TextView/> //这是一个空行
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="账  号:"
            android:textSize="18sp"
            android:gravity="center_horizontal"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="邮箱或手机号"/>

        <TextView />

    </TableRow>
    <TableRow>
        <TextView/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密  码:"
            android:textSize="18sp"
            android:gravity="center_horizontal"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="输入6-16位数字或字母"/>

        <TextView />

    </TableRow>
    <TableRow>
        <TextView/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注  册:"/>

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="登  录"

            />

        <TextView />
    </TableRow>
    <TableRow>
        <TextView/>
        <TextView/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="忘记密码?"
            android:textColor="#FF4500"
            android:gravity="right"/>
        <TextView />
    </TableRow>
</TableLayout>

标签:管理器,表格,布局,第二列,android,tools
From: https://www.cnblogs.com/tupo/p/16807615.html

相关文章