安卓基本布局(下)

TableLayout

常用属性 描述
collapseColumns 设置需要被隐藏的列的列号。
shrinkColumns 设置允许被伸缩的列的列号。
stretchColumns 设置允许被拉伸的列的列号。
xml 复制代码
<TableLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:collapseColumns="0,2"
    android:shrinkColumns="3"
    android:stretchColumns="1">
    <TableRow>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="one" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="two" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="three" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="four" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="five" />
    </TableRow>
</TableLayout>

FrameLayout帧布局

这个布局直接在屏幕上开辟出一块空白的区域,当我们往里面添加控件的时候,会默认把他们放到这块区域的左上角。帧布局的大小由控件中最大的子控件决定,如果控件的大小一样大的话,那么同一时刻就只能看到最上面的那个组件,后续添加的控件会覆盖前一个。

xml 复制代码
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/FrameLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FrameLayoutActivity">

    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#FF6143" />
    <TextView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:background="#7BFE00" />
    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#FFFF00" />

</FrameLayout>

GridLayout

与表格布局类似,但是比表格布局灵活。

常用属性 描述
orientation 设置排列方式。vertical:竖直(默认);horizontal:水平。
layout_gravity 设置对齐方式。
rowCount 设置行数。
columnCount 设置列数。
layout_row 设置第几行。
layout_column 设置第几列。
layout_rowSpan 设置横跨几行。
layout_columnSpan 设置横跨列数。
xml 复制代码
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/GridLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:columnCount="5"
    android:orientation="horizontal"
    android:rowCount="5" >

    <Button
        android:layout_gravity="fill"
        android:text="1"
        android:layout_columnSpan="3"/>
    <Button
        android:layout_gravity="fill"
        android:text="2"
        android:layout_column="1"
        android:layout_rowSpan="3"/>
    <Button android:text="3" />
    <Button
        android:text="4"
        android:layout_row="2"/>
    <Button android:text="5" />
    <Button android:text="6" />
    <Button android:text="7" />
    <Button android:text="8" />
    <Button android:text="9" />

</GridLayout>
相关推荐
人生何处不修行3 分钟前
实战:Android 15 (API 35) 适配 & 构建踩坑全记录
android
用户2018792831679 分钟前
gralde的《依赖契约法典》
android
望获linux12 分钟前
【Linux基础知识系列】第四十三篇 - 基础正则表达式与 grep/sed
linux·运维·服务器·开发语言·前端·操作系统·嵌入式软件
喜欢吃豆16 分钟前
深入企业内部的MCP知识(三):FastMCP工具转换(Tool Transformation)全解析:从适配到增强的工具进化指南
java·前端·人工智能·大模型·github·mcp
用户15517339388321 分钟前
前后端处理 `multipart/form-data` 混合参数(实体对象+文件)方案
java
东阳马生架构24 分钟前
订单初版—3.支付和履约链路中的技术问题说明文档
java
留不住丨晚霞1 小时前
说说SpringBoot常用的注解?
java·开发语言
华科云商xiao徐1 小时前
Java多线程爬虫动态线程管理实现
java·爬虫·数据挖掘
hardStudy_h1 小时前
C++——内联函数与Lambda表达式
开发语言·jvm·c++
柒七爱吃麻辣烫1 小时前
八股文系列-----SpringBoot自动配置的流程
java·spring boot·rpc