Android控件布局(浅谈5种布局)

这篇博客探讨了Android中的五种布局:LinearLayout、RelativeLayout、FrameLayout、TableLayout和已被废弃的AbsoluteLayout。LinearLayout通过orientation属性实现水平或垂直布局,支持weight属性调整控件大小。RelativeLayout依赖于控件间的关系定义位置。FrameLayout允许控件重叠,常用于刮刮卡效果。TableLayout以表格形式排列控件,结合TableRow使用。而AbsoluteLayout使用具体的X,Y坐标定位控件,但已不推荐使用。" 100159534,7533710,使用Neo4j-import高效导入千万级数据,"['图数据库', 'Neo4j导入', '数据转换', '数据库管理', '数据导入']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

学习:布局和控件的使用,学会搭建常用布局。
程序调试的方法,使用logcat定位日志。
样式和主题国际化

布局的类型:LinearLayout(线性布局)、RelativeLayout(相对布局)、FrameLayout(帧布局)、TableLayout(表格布局)、Absolute(绝对布局)

1.LinearLayout线性布局:主要以水平和竖直方式来显示界面中的控件。左右,上下。
在线性布局中有一个特别重要的属性: orientation,它的值为 vertical(竖直) horizontal(水平)

控件属性: layout.width以及layout.height 它们的值: wrap_content:包裹内容, match_parent:填充父局。
Layout.weight。权重 1:2 2:3 等等。

2.RelativeLayout相对布局:是通过相对定位的方式来指定控件的位置,既以其他控件或父容器为参照物,摆放控件的位置。 要注意依赖关系,后加入的要依赖前加入的
相对布局的属性:在这里插入图片描述

3.FrameLayout帧布局:该布局为每个加入其中的控件创建一个空白区域(为一帧,每个控件占据一帧)。 所有控件默认的位置为左上方,并按照先后顺序进行重叠摆放。在这里插入图片描述

在Android UI开发中,常见的刮刮卡是通过(FrameLayout)实现的

4.TableLayout表格布局:是以表格的形式排列控件的,通过行和列将界面划分为很多个单元格,每个单元格都可以添加控件。表格布局需要和TableRow配合使用,每一行都由TableRow对象组成,因此TableRow的数量决定表格的行数。 TableLayout继承LinearLayout类,继承父类的属性和方法。在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="2">
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="11"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="12"
            android:layout_column="1"/>

    </TableRow>
     <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:text="22" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           android:layout_column="2"
            android:text="23"/>
    </>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="2"
            android:text="33"/>
    </TableRow>
</TableLayout>

在这里插入图片描述

5.AbsoluteLayout绝对布局:指通过特定的X,Y值来控制每个控件的位置。(已经被谷歌废弃掉)
控件属性:
在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值