文章目录

  • 一、View视图
  • 二、常见布局
  • 0.布局的通用属性
  • 1.线性布局 (水平/垂直方向排列)
  • 2.相对布局(通过相对定位排列)
  • 3.帧布局(开辟空白区域,帧力的控件(层)叠加)
  • 4.表格布局(表格形式排列)
  • 5.约束布局(可视化的方式编写布局)



提示:以下是本篇文章正文内容,下面案例可供参考

一、View视图

所有UI元素都是通过View和ViewGroup构建的。

Android界面布局 android界面布局实例_控件

二、常见布局

0.布局的通用属性

属性名称

功能描述

android:id

设置布局的标识

android:layout_width

设置布局的宽度

android:layout_width

设置布局的宽度

android:layout_heigh

设置布局的高度

android:background

设置布局的背景

android:layout_margin

设置当前布局与屏幕编辑或与周围控件的距离

android:padding

设置当前布局与该布局中控件的距离

1.线性布局 (水平/垂直方向排列)

LinearLayout

控件属性

功能描述

android:id

属性

android:layout_width


android:layout_height


android:background

背景颜色

android:orientation=“horizontal”

水平

android:orientation=“vertical”

垂直

android:layout_marginRight

右外边距

android:layout_marginLeft

左外边距

android:layout_marginTop

上外边距

android:layout_marginBottom

下外边距

android:padding

内边距 (与控件的边距)

android:layout_weight=“1”

权重

当控件使用权重属性式,布局宽度属性通常设置为0dp


2.相对布局(通过相对定位排列)

**RelativeLayout**

控件属性

功能描述

android:layout_centerInParent

设置当前控件位于父布局的中央位置

android:layout_centerVerical

设置当前控件位于父布局的垂直居中位置

android:layout_centerHorizontal

设置当前控件位于父布局的水平居中位置

android:layout_above

设置当前控件位于某控件上方

android:layout_below

设置当前控件位于某控件下方

android:layout_toLeftOf

设置当前控件位于某控件左侧

android:layout_toRightOf

设置当前控件位于某控件右侧

android:layout_alignParentTop

设置当前控件是否与父控件顶端对齐

android:layout_alignParentLeft

设置当前控件是否与父控件左对齐

android:layout_alignParentRight

设置当前控件是否与父控件右对齐

android:layout_alignParentBotttom

设置当前控件是否与父控件底端对齐

android:layout_aligbTop

设置当前控件的上边界与某控件的上边界对齐

android:layout_aligbBottom

设置当前控件的下边界与某控件的下边界对齐

android:layout_aligbLeft

设置当前控件的左边界与某控件的左边界对齐

android:layout_aligbRight

设置当前控件的右边界与某控件的右边界对齐


3.帧布局(开辟空白区域,帧力的控件(层)叠加)

FrameLayout

android:foregroundGravity="left"
设置前景图像的显示位置
android:foreground:"@XXX"
设置帧布局容器的前景图片,始终再所有子控件之上


4.表格布局(表格形式排列)

TableLayout

表格布局属性

功能描述

android:stretchColumns

设置该列被拉伸

android:shrinkColumns

设置该列被拉伸

android:coolapseColumns

设置该列被拉伸

表格布局控件属性

功能描述

android:layout_column

设置该单元显示位置

android:layout_span

设置该单元格占据几行,默认为1行

<?xml version="1.0" encoding="utf-8"?>

<!--TableLayout   表格布局-->

<!--表格布局属性-->
<!--stretchColumns  被拉伸-->
<!--shrinkColumns 被收缩-->
<!--collapseColumns  被隐藏-->
<TableLayout xmlns:android="http:///apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:stretchColumns="1"
    >

    <TableRow>
        <Button android:text="按钮1"></Button>
        <Button android:text="按钮1"></Button>
        <Button android:text="按钮1"></Button>
        <TextView android:text="文本信息"></TextView>
        <Button android:text="按钮1"></Button>
    </TableRow>

    <TableRow>
        <Button android:text="按钮1"></Button>
        <Button android:text="按钮1"></Button>
        <Button android:text="按钮1"></Button>
    </TableRow>

    <TableRow>
        <Button android:text="按钮1"></Button>
        <Button android:text="按钮1"></Button>
    </TableRow>

    <!--表格布局控件属性-->
    <!--layout_column  设置该单元格显示位置-->
    <!--layout_span 显示大小-->

    <TableRow >
        <Button android:text="按钮1" android:layout_column="1"></Button>
        <Button android:text="按钮1"  android:layout_span="3"></Button>

    </TableRow>

</TableLayout>

Android界面布局 android界面布局实例_java_02


5.约束布局(可视化的方式编写布局)