1.相对布局
代码:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button1"

android:layout_marginTop="260dp"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true" />

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toRightOf="@id/button1"

android:text="Button2"

android:layout_alignBottom="@id/button1"

android:layout_marginBottom="100dp"/>

</RelativeLayout>

如图:

2.线性布局
代码:

<?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/button3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button" />

<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button" />

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button" />

</LinearLayout>

如图:


3.表格布局
表格布局就是让控件以表格的形式来排列组件的,只要将组件或信息放在单元格中,控件就可以整齐的排列
在TableLayout中,行数是由TableRow对象控制的,即对象中有多少个TableRow,就有多少行。
代码:

<?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="match_parent">

<TableRow

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/tableRow1"

>

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button1"

android:layout_column="0"/>

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button2"

android:layout_column="1"/>

</TableRow>

<TableRow

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/tableRow2">

<Button

android:id="@+id/button3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button3"

android:layout_column="1"/>

<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button4"

android:layout_column="2"/>

</TableRow>

<TableRow

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/tableRow3">

<Button

android:id="@+id/button5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button5"

android:layout_column="2"/>

</TableRow>

</TableLayout>

如图:

4.网格布局
代码:

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

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:columnCount="4"

android:orientation="horizontal">

<Button

android:layout_column="3"

android:text="/" />

<Button

android:text="1" />

<Button

android:text="2" />

<Button

android:text="3" />

<Button

android:text="*" />

<Button

android:text="4" />

<Button

android:text="5" />

<Button

android:text="6" />

<Button

android:text="-" />

<Button

android:text="7" />

<Button

android:text="8" />

<Button

android:text="9" />

<Button

android:text="+"

android:layout_gravity="fill"

android:layout_rowSpan="3"/>

<Button

android:text="0"

android:layout_gravity="fill"

android:layout_columnSpan="2"/>

<Button

android:text="00" />

<Button

android:text="="

android:layout_gravity="fill"

android:layout_columnSpan="3"/>

</GridLayout>

如图:

5.帧布局
代码:

<?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/button1"

android:layout_width="294dp"

android:layout_height="294dp"

android:text="Button1"

android:visibility="visible" />

<Button

android:id="@+id/button2"

android:layout_width="218dp"

android:layout_height="214dp"

android:text="Button2"

android:visibility="visible" />

<Button

android:id="@+id/button3"

android:layout_width="156dp"

android:layout_height="143dp"

android:text="Button3"

android:visibility="visible" />

</FrameLayout>

如图:

6. 绝对布局

代码:

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

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent">

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button1"

android:layout_y="50dp"

android:layout_x="50dp"/>

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button2"

android:layout_x="200dp"

android:layout_y="200dp"/>

</AbsoluteLayout>

如图:

Android studio中的6大布局的更多相关文章

  1. Android Studio中配置及使用OpenCV示例

    Android Studio配置及使用OpenCV 前言:最近在做项目移植,项目较大,在Eclipse中配置的Jni及OpenCV环境没任何问题,但是迁移到Studio中就问题一大堆,网上也找了一些资 ...

  2. Android ImageView 不显示JPEG图片 及 Android Studio中怎样引用图片资源

    Android ImageView 不显示JPEG图片 今天在写一个小实例,ImageView在xml里面设置的是INVISIBLE,在代码里须要设置成setVisibility(View.VISIB ...

  3. Android编程权威指南笔记3:Android Fragment讲解与Android Studio中的依赖关系,如何添加依赖关系

    Android Fragment 当我在学习时,了解了Fragment词汇 Fragment是一种控制器对象,我就把所了解的简单说一下.activity可以派fragment完成一些任务,就是管理用户 ...

  4. Android开发的小技巧,在Android Studio中使用Designtime Layout Attributes

    在编写xml文件时,为了预览效果,经常会使用默认填上一些内容,比如TextView时,随便写上一个text <TextView ... android:text="Name:" ...

  5. Android Studio 中 FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileDebugAidl'.的问题解答

    Android Studio 中 FAILURE: Build failed with an exception. * What went wrong: Execution failed for ta ...

  6. Android Studio中有用的快捷键栏

    Android Studio中有用的快捷键栏#1 Ahraewi线移动 Alt + Shift +向上/向下❖Alt + Shift +向上/向下 或上下移动在所选位置的行. 删除行 CMD + B ...

  7. 在Android Studio中进行单元测试和UI测试

    本篇教程翻译自Google I/O 2015中关于测试的codelab,掌握科学上网的同学请点击这里阅读:Unit and UI Testing in Android Studio.能力有限,如有翻译 ...

  8. 浅谈Windows下SVN在Android Studio中的配置、基本使用及解除关联

    看到网上很多关于svn环境配置和关联Android-Studio的很多博文,发现很零散,想集大家所长整理一下: 在AndroidStudio中开发版本控制中,除了Git就是SVN,和Eclipse不同 ...

  9. Android studio 中引用jar的其实是Maven?(二)

    上一篇:Android studio 中引用jar的其实是Maven?(一) 搭建maven仓库: 去了解一个新的事物的时候,最好的方式就是去使用它.例如去了解一座城市的时候,最好的方式就是乘坐公共交 ...

随机推荐

  1. 7.2 基础知识ArrayMap

    1.android源码中维护有键值对,通过键可以找到值 Java中Object是所有类的父类,对于键值对的保存如果使用个ObjectArray数组,比如N个位置存放键,N+1的位置就存放值,那么如果键 ...

  2. keil出现蓝色小箭头

  3. [慕课笔记]mongodb入门篇

    一:对mongodb有一个系统的完备的了解,只有概念清楚了,才能更好的使用 二:学会mongodb数据库的搭建 首先:了解如何部署数据库的服务 搭建简单的单机服务到搭建具有冗余容错功能的复制集再到搭建 ...

  4. Python 细节与基础拾遗

    locals():当前环境下的全部局部变量,字典(dict)类型,所有的 key 均为字符串类型: if 'sess' in locals() and sess is not None: print( ...

  5. POJ 1751 Highways (ZOJ 2048 ) MST

    http://poj.org/problem?id=1751 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2048 题目大 ...

  6. [转载]Ocelot简易教程(六)之重写配置文件存储方式并优化响应数据

    作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9807125.html 很多人都说配置文件的配置很繁琐,如果存储在数据库就方便很多,可以通过自定义UI界面 ...

  7. jsp页面无法解析EL表达式问题

    Servlet版本的问题.原来Servlet中可以设定是否解析EL表达式,只有2.4版本的Servlet默认是解析EL表达式的,而其他版本是默认不解析EL表达式.于是把web.xml中使用的2.5版本 ...

  8. windows cmd 查看文件目录树

    windows + R ⇒ 输入 cmd ⇒ 进入 windows 命令行界面: tree/?:命令提示: tree:不输入任何参数,输出一棵目录树 不显示文件,只显示目录: tree/F:递归显示目 ...

  9. yield return

    一次被yield return坑的历程.   事情的经过是这样的: 我用C#写了一个很简单的一个通过迭代生成序列的函数. public static IEnumerable<T> Iter ...

  10. iOS开发之Quartz2D 二:绘制直线,曲线,圆弧,矩形,椭圆,圆

    #import "DrawView.h" @implementation DrawView /** * 作用:专门用来绘图 * 什么时候调用:当View显示的时候调用 * @par ...