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

学习:布局和控件的使用,学会搭建常用布局。
程序调试的方法,使用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值来控制每个控件的位置。(已经被谷歌废弃掉)
控件属性:
在这里插入图片描述
在这里插入图片描述

发布了9 篇原创文章 · 获赞 13 · 访问量 2789

猜你喜欢

转载自blog.csdn.net/weixin_44696542/article/details/104482507
今日推荐