一.android中五大布局相当于是容器,这些容器里可以放控件也可以放另一个容器,子控件和布局都需要制定属性。

1.相对布局:RelativeLayout

@1控件默认堆叠排列,需要制定控件的相对位置

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我 "/> <Button
android:id="@+id/bt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/bt1"
android:text="爱 "/>
<Button
android:id="@+id/bt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/bt2"
android:text="你"/> </RelativeLayout>

效果:

2.线性布局:LinearLayout

@1.控件线性排列,分为水平和垂直排列

@2.可以指定背景图片,透明度以及颜色

android:background="@android:color/holo_blue_bright"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我 "/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我 "/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我 "/> </LinearLayout>

垂直效果:

水平效果:

3.帧布局:FrameLayout

@1控件可以重叠的布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30"
android:text="我 "/> <Button
android:id="@+id/bt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60"
android:text="爱 "/>
<Button
android:id="@+id/bt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/bt2"
android:text="你"/> </FrameLayout>

效果:

4.表格布局:TableLayout

@1控件呈现表格方式排列

@2TableRow用于制定表格的一行

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:collapseColumns="3"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我 "/> <Button
android:id="@+id/bt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="爱 "/> <Button
android:id="@+id/bt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="爱 "/> </TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/bt4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我 "/> <Button
android:id="@+id/bt5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="爱 "/> <Button
android:id="@+id/bt6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你"/> </TableRow>
<TableRow>
<Button
android:id="@+id/bt8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我 好累"/> <Button
android:id="@+id/bt9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="爱 "/>
<Button
android:id="@+id/bt10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你"/> </TableRow> </TableLayout>

效果:

5.方格布局:GridLayout

@1可以指定控件位于第几行第几列

代码:

 <?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <Button
android:id="@+id/bt4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我 "/> <Button
android:id="@+id/bt5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="爱 "/> <Button
android:id="@+id/bt6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你"/> <Button
android:id="@+id/bt8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我 好累"/> <Button
android:id="@+id/bt9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="1"
android:text="爱 "/>
<Button
android:id="@+id/bt10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="3"
android:text="你"/> </GridLayout>

效果:

android中的五大布局(控件的容器,可以放button等控件)的更多相关文章

  1. Android中的五大布局

    Android中的五大布局 1.了解布局 一个丰富的界面总是要由很多个控件组成的,那我们如何才能让各个控件都有条不紊地 摆放在界面上,而不是乱糟糟的呢?这就需要借助布局来实现了.布局是一种可用于放置很 ...

  2. Android中的五大布局和logcat打印日志

    在android中的布局有五大类,有的时候你可能用到一种,但有的时候你也可能需要两种或者三种布局同时一起使用.这五种布局为别为:LinearLayout(线性布局),FrameLayout(框架布局) ...

  3. 兔子--Android中的五大布局

    LinearLayout:被称为线性布局,分为水平和垂直,设置的垂直或水平的属性值,来排列全部的子元素.全部的子元素都被堆放在其他元素之后,因此一个垂直列表的每一行仅仅会有一个元素,而无论他们有多宽, ...

  4. Android学习笔记(第二篇)View中的五大布局

    PS:人不要低估自己的实力,但是也不能高估自己的能力.凡事谦为本... 学习内容: 1.用户界面View中的五大布局... i.首先介绍一下view的概念   view是什么呢?我们已经知道一个Act ...

  5. Android开发-之五大布局

    在html中大家都知道布局是什么意思了,简单来说就是将页面划分模块,比如html中的div.table等.那么Android中也是这样的.Android五大布局让界面更加美化,开发起来也更加方便.当然 ...

  6. Android中的LinearLayout布局

    LinearLayout : 线性布局 在一般情况下,当有很多控件需要在一个界面列出来时,我们就可以使用线性布局(LinearLayout)了,  线性布局是按照垂直方向(vertical)或水平方向 ...

  7. android中的常用布局管理器(三)

    接上篇博客 (5)TableLayout     表格布局管理器 在android中,线性布局和表格布局用的是最多的. 在很多的输出操作中,往往会使用表格的形式对显示的数据进行排版,tablelayo ...

  8. Android 中常用的布局

    一.线性布局----LinearLayout   horizontal 水平 <?xml version="1.0" encoding="utf-8"?& ...

  9. Android成长日记-五大布局

    1. 五布局之线性布局LinearLayout 特点:它包含的子控件将以横向或竖向的方式排列 ps:android:gravity=”center|bottom”(gravity允许多级联用) Tip ...

随机推荐

  1. 一个高性能异步socket封装库的实现思路 (c#)

    前言 socket是软件之间通讯最常用的一种方式.c#实现socket通讯有很多中方法,其中效率最高就是异步通讯. 异步通讯实际是利用windows完成端口(IOCP)来处理的,关于完成端口实现原理, ...

  2. 开源API测试工具 Hitchhiker v0.5更新 - 完善细节

    Hitchhiker 是一款开源的支持多人协作的 Restful Api 测试工具,支持Schedule, 数据对比,压力测试,支持上传脚本定制请求,可以轻松部署到本地,和你的team成员一起管理Ap ...

  3. SpringCloud学习笔记(3)——Hystrix

    参考Spring Cloud官方文档第13.14.15章 13. Circuit Breaker: Hystrix Clients Netflix提供了一个叫Hystrix的类库,它实现了断路器模式. ...

  4. thinkhphp 上传文件或者图片

  5. POJ3211--分类01背包

    Washing Clothes Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 9700 Accepted: 3110 Desc ...

  6. Python 简单的输出

    Python hw其实非常简单. 2 行代码 vi test.py [Python] 纯文本查看 复制代码 ? 1 2 #!/usr/bin/python print "Hello Worl ...

  7. python3 中encode 和decode的使用方法。

    编码: 将文本转换成字节流的过程.即Unicode----------->特定格式的编码方式,产生特定的字节流保存在硬盘中(一般为utf-8格式). 解码: 将硬盘中的字节流转换成文本的过程.即 ...

  8. 第三节:Creating API Endpoints (创建API路由)

    对于这篇文章的标题,其实,直译就是创建api端点.但是,真的很难懂,我还是写为API路由吧.每篇,文章,我都会全部去进行实践操作,力求写一个好点的教程. 本文英文地址-->https://git ...

  9. 《RabbitMQ Tutorial》译文 第 4 章 路由

    原文来自 RabbitMQ 英文官网的教程(4.Routing),其示例代码采用了 .NET C# 语言. In the previous tutorial we built a simple log ...

  10. 通过反射实现Microsoft Visual Studio International Pack 1.0 SR1里面的两个类

    这两天打算实现拼音和简繁转换的方法, 发现Microsoft Visual Studio International Pack 1.0 SR1 提供了 .    下载地址 但是基于某些原因, 一来下载 ...