线性布局:

<?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" ><!-- 垂直 vertical--> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一个textView" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一个textView"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一个textView" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一个textView"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一个textView"/> </LinearLayout>

<?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" ><!-- 垂直 vertical--> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一个textView" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一个textView"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一个textView" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一个textView"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一个textView"/> </LinearLayout>

相对布局:所有的控件默认都是从左上角开始画的。安卓默认的布局就是相对布局。

<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> </RelativeLayout>

相对布局它可以通过id来指定相互的位置。

<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textview2"
android:layout_below="@id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> </RelativeLayout>

<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textview2"
android:layout_below="@id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textview2" />
<TextView
android:id="@+id/textview3"
android:layout_toRightOf="@id/textview2"
android:layout_alignBottom="@id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> </RelativeLayout>

相对布局不仅可以指定控件之间相对的位置,咱们还可以针对父容器去挪一个位置。配置它在父容器的正中间。

    <TextView
android:id="@+id/textview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="@string/hello_world" />

所以相对来说相对布局它摆放控件的位置会更灵活。不但可以让它在每个控件之间指定相对的位置。可以写一个控件然后依照这个控件在它的前后左右上下去摆控件。也可以让它针对父容器放在父容器的上边下边左边右边中间,可以指定相互的这些位置。这个就是相对布局。

<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textview2"
android:layout_below="@id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textview2" />
<TextView
android:id="@+id/textview3"
android:layout_toRightOf="@id/textview2"
android:layout_alignBottom="@id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="@string/hello_world" /> </RelativeLayout>

帧布局/框架布局   也是从屏幕的左上角开始画。

android:layout_margin="10dp"可以指定外边距。

    <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:layout_margin="100dp"
android:text="TextView" />
    <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:layout_marginRight="100dp"
android:text="TextView" />

所以在framework框架布局里面除了用外边距和内边距的方式能够挪位置之外没有别的方法。只能通过android:layout_gravity在框架布局framework layout里面最终能够放的就是9个位置。最上面、中间、最下面的左中右。

开发当中用的比较多的是线性布局和相对布局,然后就是framework layout。


剩下两个不太常用。

table layout就类似于竖直方向的线性布局。

不指定<TableRow>默认占据着一整行.<TableRow>就是水平方向的线性布局.不指定<TableRow>就是竖直方向的线性布局.


最后一个是绝对布局。

AbsoluteLayout is deprecated

绝对布局是过时的了.绝对布局通过一个具体的坐标来确定控件的位置。随着安卓的设备发展的越来越快发展的越来越多,设备的尺寸千差万别。在这个设备上看的挺好换一个设备就跑偏了.换一个大的屏幕可能就偏的更厉害。所以绝对布局就被放弃掉了.


相对布局是用的最多的.接下来是线性布局.框架布局.表格布局.绝对布局已经不用了.

18_andriod常用布局&内容回顾的更多相关文章

  1. rem自适应布局的回顾总结

    使用rem实现自适应布局,应该算是当前移动前端的一大趋势,有些人对此还有点迷惑,搞不懂rem是如何实现自适应布局,如何根据设计稿来调整rem的值?rem布局如何用雪碧背景图片?rem一定要加载JS吗? ...

  2. python:页面布局 后台管理页面之常用布局

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  3. WPF中的常用布局

    一 写在开头1.1 写在开头评价一门技术的好坏得看具体的需求,没有哪门技术是面面俱到地好. 1.2 本文内容本文主要内容为WPF中的常用布局,大部分内容转载至https://blog.csdn.net ...

  4. Android开发工程师文集-Fragment,适配器,轮播图,ScrollView,Gallery 图片浏览器,Android常用布局样式

    Android开发工程师文集-Fragment,适配器,轮播图,ScrollView,Gallery 图片浏览器,Android常用布局样式 Fragment FragmentManager frag ...

  5. ExtJs常用布局--layout详解(含实例)

    序言: 笔者用的ExtJs版本:ext-3.2.0 ExtJs常见的布局方式有:border.form.absolute.column.accordion.table.fit.card.anchor ...

  6. WPF中的常用布局 栈的实现 一个关于素数的神奇性质 C# defualt关键字默认值用法 接口通俗理解 C# Json序列化和反序列化 ASP.NET CORE系列【五】webapi整理以及RESTful风格化

    WPF中的常用布局   一 写在开头1.1 写在开头微软是一家伟大的公司.评价一门技术的好坏得看具体的需求,没有哪门技术是面面俱到地好,应该抛弃对微软和微软的技术的偏见. 1.2 本文内容本文主要内容 ...

  7. Android常用布局和控件

    一.Android常用布局属性 1. LinearLayout的特有属性 android:orientation:设置布局排列方式   android:layout_weight:设置所占布局的权重  ...

  8. 基本数据类型-集合(set)_上周内容回顾(字符串_数字_列表_元组_字典_集合)

    上周内容回顾 1.字符串 2.数字 除了布尔类型外,int.long.float和complex都可以使用的运算为:加.减.乘.除.整除.幂运算和取余 3.列表和元组 列表的内容可变,可以包含任意对象 ...

  9. 常用布局,div竖直居中

    常用两列布局,多列布局和div竖直居中 body { margin:; padding:; } .w200 { width: 200px; } .mar-left200 { margin-left: ...

随机推荐

  1. NPM安装配置

    http://www.tuicool.com/articles/mmYZBn http://npm.taobao.org/ 安装Nodejs后即可开始NPM之旅了,新建一个package.json或者 ...

  2. Data Structure Array: Move all zeroes to end of array

    http://www.geeksforgeeks.org/move-zeroes-end-array/ #include <iostream> #include <vector> ...

  3. Please enable network time synchronisation in system settings

    eth区块同步出现这样的WARN: WARN [06-17|13:02:42] System clock seems off by -51.509894715s, which can prevent ...

  4. 第五篇、css补充二

    一.内容概要 1.图标 2.目录规划 3.a标签中的img标签在浏览器中的适应性 4.后台管理系统设置 5.边缘提示框 6.登录页面图标 7.静态对话框 8.加减框 补充知识: line-height ...

  5. MySQL 及 SQL 注入与防范方法

    所谓SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令. 我们永远不要信任用户的输入,我们必须认定用户输入的数据都是不安全的, ...

  6. Django之Form详解

    Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 1.创建Form类.View函数处理 from ...

  7. DB2常见错误

    +098 01568 动态SQL语句用分号结束+100 02000 没有找到满足SQL语句的行+110 01561 用DATA CAPTURE定义的表的更新操作不能发送到原来的子系统+111 0159 ...

  8. 什么是tmpfs

    什么是tmpfs tmpfs是Linux/Unix系统上的一种基于内存的文件系统.tmpfs可以使用您的内存或swap分区来存储文件. 实现原理:基于VM子系统 tmpfs是基于Linux的虚拟内存管 ...

  9. 剑指offer之 从上往下打印二叉树

    import java.util.ArrayList; import java.util.LinkedList; /** public class TreeNode { int val = 0; Tr ...

  10. QT 巧用QSignalMapper分类有序地处理大量信号

    转自--> http://blog.csdn.net/cuteqt/article/details/4306900 QSignalMapper这个类并不是个新鲜概念, 早在Qt2里就已经存在, ...