AndroidStudio里面支持的布局有挺多种的,但是最最重要的是RelativeLayout(相对布局)和LinearLayout(线性布局),熟练掌握这两种布局也非常够用了,当然还有FrameLayout(帧布局)…但是对于初学者,先学会了相对布局和线性布局,再去学习其他布局,就会觉得非常简单轻松了。


一.线性布局(LinearLayout)

当我们使用线性布局时,可以发现文字去了左上角,不在中间了。

如果只有一个子控件,则不需要写orientation属性,有多个要写。orientation=“horizontal”表示水平,orientation=“vertical”表示垂直。

在线性布局中,有两个属性:layout_width,layout_height。这两个属性就决定了布局的宽度和高度。

这两个属性的大小由match_parent,wrap_content,自己定义大小决定的。

1.match_parent只会占满剩余的空间,根据不同的方向去占满。

(我们发现,它占用了整个宽度,并覆盖了右侧的文字,如果换做layout_height,则高度上会占满)

2.wrap_content只会占用自己的那部分。

3.自己定义可以写(可以写固定数值,单位是dp或者dip,不能用px)

二.相对布局(RelativeLayout)

没有方向性,但是有z轴,代码在后的z轴值越大,既可以是悬浮叠加。必须要有参照物。

1.布局本身

centerInparent

centerVertical

centerHorizontal

alignParentTop

alignParentBottom

alignParentLeft

alignParentRight

2.通过id来指定参照物

同理,

<?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">
<TextView
android:id="@+id/tv_center"<!--设置参照物-->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="居中"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="右下角"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="右上角"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="左下角"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左上角"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/tv_center"<!--应用参照物-->
android:text="center左上角"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/tv_center"<!--应用参照物-->
android:layout_centerInParent="true"
android:text="center上面"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_center"<!--应用参照物-->
android:layout_centerInParent="true"
android:text="center下面"
/>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/tv_center"<!--应用参照物-->
android:layout_centerVertical="true"
android:text="center右面"
/>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/tv_center"<!--应用参照物-->
android:layout_centerVertical="true"
android:text="center左面"
/> </RelativeLayout>

AS的不同布局的更多相关文章

  1. 前端框架 EasyUI (2)页面布局 Layout

    在 Web 程序中,页面布局对应用程序的用户体验至关重要. 在一般的信息管理类的 Web 应用程序中,页面结构通常有一个主工作区,然后在工作区上下左右靠近边界的区域设置一些边栏,用于显示信息或放置一些 ...

  2. TODO:Laravel 使用blade标签布局页面

    TODO:Laravel 使用blade标签布局页面 本文主要介绍Laravel的标签使用,统一布局页面.主要用到到标签有@yield,@ stack,@extends,@section,@stop, ...

  3. CSS HTML元素布局及Display属性

    本篇文章主要介绍HTML的内联元素.块级元素的分类与布局,以及dispaly属性对布局的影响. 目录 1. HTML 元素分类:介绍内联元素.块级元素的分类. 2. HTML 元素布局:介绍内联元素. ...

  4. 谈谈一些有趣的CSS题目(六)-- 全兼容的多列均匀布局问题

    开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...

  5. Xamarin+Prism开发详解五:页面布局基础知识

    说实在的研究Xamarin到现在,自己就没设计出一款好的UI,基本都在研究后台逻辑之类的!作为Xamarin爱好者,一些简单的页面布局知识还是必备的. 布局常见标签: StackLayout Abso ...

  6. 界面设计技法之css布局

    css布局之于页面就如同ECMAScript之于JS一般,细想一番,html就如同语文,css就如同数学,js呢,就是物理,有些扯远,这里就先不展开了. 回到主题,从最开始的css到如今的sass(l ...

  7. Android如何制作漂亮的自适布局的键盘

    最近做了个自定义键盘,但面对不同分辨率的机型其中数字键盘不能根据界面大小自已铺满,但又不能每种机型都做一套吧,所以要做成自适应,那这里主讲思路. 这里最上面的titlebar高度固定,下面输入的金额高 ...

  8. 页面布局class常见命名规范

    头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wrapper 左右中:left rig ...

  9. Flex 布局教程:语法篇

    作者: 阮一峰 网页布局(layout)是CSS的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display属性 + position属性 + float属性.它对于那些特殊布局非常不方便 ...

  10. CSS3新特性应用之结构与布局

    一.自适应内部元素 利用width的新特性min-content实现 width新特性值介绍: fill-available,自动填充盒子模型中剩余的宽度,包含margin.padding.borde ...

随机推荐

  1. VirtualBox--修改虚拟硬盘大小

    学习:Oracle VM VirtualBox做好虚拟硬盘后,如何进一步修改虚拟硬盘的大小 修改为50G,修改后在虚拟机中查看:Machine→Settings→Storage VBoxManage ...

  2. Java 将XML转为PDF

    可扩展标记语言(XML)文件是一种标准的文本文件,它使用特定的标记来描述文档的结构以及其他特性.通过将XML转换为PDF,能够便于文件传输及共享.本文,将介绍通过Java代码来实现该格式转换的方法. ...

  3. Caffe2源码解析之core

    写在前面 在对Tensorflow的后端源码进行了拆解(参见tensorflow源码解析系列文章索引)之后,很想跟其它深度学习框架的实现进行对比,根据框架的流行程度,先选择了Pytorch.Pytor ...

  4. SP1480题解

    <四重计树法> 有标号无根 prufer 序列,\(n^{n-2}\). 有标号有根 prufer 序列,\(n^{n-1}\). 无标号有根 设 \(f[n]\) 为 \(n\) 个节点 ...

  5. Java基础—构造方法

    1.构造方法概述 构造方法是一种特殊的方法,用来创建对象,当我们不定义时,系统会默认给出一个无参构造方法:一旦我们定义了任意的构造方法,系统就不会给出默认的无参构造方法 格式如下: public ca ...

  6. prometheus虚拟化安装脚本

    在线安装下载链接:https://files.cnblogs.com/files/blogs/705493/online_prometheus.sh 离线安装下载链接:https://files.cn ...

  7. ArcGIS Server 禁用/rest/services路径(禁用服务目录)

    ArcGIS Server服务目录(路径如:http://<hostname>:6080/arcgis/rest/services)默认可以不需要登陆直接打开.效果如下图. ArcGIS服 ...

  8. SQLMap参数命令

    SQLMap参数命令   --method=<http方法> 指定使用的http方法 --data=<post数据> 提交post数据并对post数据进行测试 --param- ...

  9. 绕过CDN找到⽬标站点真实IP

    一.判断目标网站是否使用CDN 在渗透测试中,如果连真实 IP 都没有找到的话,相当于连门都没有找到.所以,如何验证目标网站是否使用了 CDN 呢? 1.多地 ping 法(一般情况下使用多地 pin ...

  10. loj#6072 苹果树(折半搜索,矩阵树定理,容斥)

    loj#6072 苹果树(折半搜索,矩阵树定理,容斥) loj 题解时间 $ n \le 40 $ . 无比精确的数字. 很明显只要一个方案不超过 $ limits $ ,之后的计算就跟选哪个没关系了 ...