安卓基本布局(下)

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>
相关推荐
2301_780789667 小时前
跨平台适配!SDK 游戏盾兼容全终端游戏场景
java·网络·ddos
第九序言T8 小时前
Python 数据处理进阶(十八)批量处理同结构文件:一个文件夹一次跑完
开发语言·python·自动化·pandas·数据处理
学长毕设8 小时前
基于springboot的食品仓库管理系统
java·spring boot·后端
步行cgn9 小时前
FormHttpMessageConverter 详解:Spring MVC 中表单数据的读写转换器
java·spring·mvc
龙亘川9 小时前
构建城市公共安全数字底座:亘川智城智慧安防系统全维度解读
java·大数据·开发语言·人工智能·信息可视化
金銀銅鐵9 小时前
[Java] 用 CLI 展示 EnumMap 增删键值对时的内部变化
java·源码·ai编程
程序喵大人9 小时前
【C++入门】内存模型与资源管理 - 09 shared_ptr 和 weak_ptr 解决共享,也带来代价
开发语言·c++·资源管理·智能指针·内存模型
秋天的怀念_David9 小时前
第二十二夜 · 数字迷雾
java·程序人生·算法
Raas10010 小时前
AI网关部署方案?从部署到上线全流程
java·开发语言·人工智能·gateway·ai网关·企业级ai网关·企业级ai产品
niucloud-admin10 小时前
NIUCLOUD PHP SAAS上门家政使用文档:城市管理
java·前端·php