一、布局总述

1

线性布局

以水平和垂直方向排列

2

相对布局

通过相对定位排列

3

帧布局

开辟空白区域,帧里的控件(层)叠加

4

表格布局

表格形式排列

5

约束布局

可视化的方式编写布局

二、线性布局

1、属性

android:id

唯一值

android:layout_height


高,

wrap_content:(随内容变化,类似auto),

match_parent:(同父元素一样)

单元最好是:dp



android:layout_width

宽,同上

android:background

背景色

android:layout_margin

外边距

android:layout_padding

内边距

android:orientation

horizontal水平排列;vertical竖直排列

android:layout_weight

View,权重平分

android:gravity

居中

1、横向排列   android:orientation="horizontal"

【Android】五种常用布局方式详解(图文+示例)持续更新中..._线性布局【Android】五种常用布局方式详解(图文+示例)持续更新中..._android_02


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"
android:layout_marginTop="20dp"

/>

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
<Button
android:id="@+id/button3"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="按钮3"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>


</LinearLayout>

1、纵向排列   android:orientation="vertical"

【Android】五种常用布局方式详解(图文+示例)持续更新中..._xml_03【Android】五种常用布局方式详解(图文+示例)持续更新中..._android_04


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"
android:layout_marginTop="20dp"

/>

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
<Button
android:id="@+id/button3"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="按钮3"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>


</LinearLayout>


.