安卓基本布局(下)

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>
相关推荐
一灯架构1 小时前
90%的人答错!一文带你彻底搞懂ArrayList
java·后端
踏着七彩祥云的小丑1 小时前
pytest——Mark标记
开发语言·python·pytest
Dream of maid2 小时前
Python12(网络编程)
开发语言·网络·php
W23035765732 小时前
经典算法:最长上升子序列(LIS)深度解析 C++ 实现
开发语言·c++·算法
Y4090012 小时前
【多线程】线程安全(1)
java·开发语言·jvm
不爱吃炸鸡柳2 小时前
Python入门第一课:零基础认识Python + 环境搭建 + 基础语法精讲
开发语言·python
布局呆星3 小时前
SpringBoot 基础入门
java·spring boot·spring
minji...3 小时前
Linux 线程同步与互斥(三) 生产者消费者模型,基于阻塞队列的生产者消费者模型的代码实现
linux·运维·服务器·开发语言·网络·c++·算法
Dxy12393102163 小时前
Python基于BERT的上下文纠错详解
开发语言·python·bert
风吹迎面入袖凉3 小时前
【Redis】Redisson的可重入锁原理
java·redis