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. 【Codeforces Round #435 (Div. 2) B】Mahmoud and Ehab and the bipartiteness

    [链接]h在这里写链接 [题意] 让你在一棵树上,加入尽可能多的边. 使得这棵树依然是一张二分图. [题解] 让每个节点的度数,都变成二分图的对方集合中的点的个数就好. [错的次数] 0 [反思] 在 ...

  2. php对xml进行简单的增删改查(CRUD)操作

    假如有以下xml文件: <?xml version="1.0" encoding="UTF-8"? > <setting>     &l ...

  3. 算法 Tricks(四)—— 判断序列中的字符/数值是否交替出现

    比如:353, 54545,数字都是交替出现的: bool alternate = true; for (int i = 0; i < M.size(); ++i){ if (M[i] != M ...

  4. ZOJ 3336 Friend Number II

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3780 题目大意: 给你一个正整数x,要求每个数字上的总和和x相同且比x大的最小 ...

  5. 算法练习--二分搜索哈希表-JS 实现

    1. 以哈希KEY的值建立二叉哈希表 2. 依据传入的哈希值使用二分法搜索 详细实现例如以下: function binarySearchTable(comp){ this.comp = comp; ...

  6. linux ps命令,查看某进程cpu和内存占用率情况, linux ps命令,查看进程cpu和内存占用率排序。 不指定

    背景:有时需要单看某个进程的CPU及占用情况,有时需要看整体进程的一个占用情况.一. linux ps命令,查看某进程cpu和内存占用率情况[root@test vhost]# ps auxUSER  ...

  7. html5-8 如何控制html5中的视频标签和音频标签

    html5-8 如何控制html5中的视频标签和音频标签 一.总结 一句话总结:找到视频或者音频的element对象,然后查手册看对应的方法或者属性就可以,里面有控制的. 1.如何控制html5中的视 ...

  8. 通过select下拉框里的value控制div显示与隐藏

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. MySQL key分区(五)

    具体描写叙述总结请看MySQL分区(一) 样例:该样例为本人个人学习总结分享->具体说明-->有问题欢迎前来交流

  10. phpStudy的localhost不能访问怎么解决(相关性)

    phpStudy的localhost不能访问怎么解决(相关性) 一.总结 1.注释掉httpd.conf文件中的#ServerName localhost:80   这句话. 2.既然是localho ...