Android布局管理器-从实例入手学习相对布局管理器的使用
场景
AndroidStudio跑起来第一个App时新手遇到的那些坑:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797243
使用相对布局RelativeLayout实现简单的登录提示的布局,效果如下

注:
博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
实现
新建之后的默认页面布局为

将其修改为RelativeLayout

相对布局只要是要有参照物,即谁在谁下方,谁在谁左边,和谁左对齐,等等。
首先新建一个TextView,并设置其ID,将其放在屏幕中间
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发现新的版本,您想现在更新吗?"
android:id="@+id/textView1"
android:layout_centerInParent="true"/>
主要通过 android:layout_centerInParent="true"/> 设置在中间。
然后将现在更新按钮通过android:layout_below="@+id/textView1"设置位于TextView的下方,通过android:layout_alignRight="@+id/textView1"/>设置与TextView右对齐。
然后再添加一个按钮使其在textView的下方以及在立即更新按钮的左边。
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="现在更新"
android:id="@+id/button2"
android:layout_below="@+id/textView1"
android:layout_toLeftOf="@+id/button1"/>
完整示例代码
<?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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发现新的版本,您想现在更新吗?"
android:id="@+id/textView1"
android:layout_centerInParent="true"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="以后再说"
android:id="@+id/button1"
android:layout_below="@+id/textView1"
android:layout_alignRight="@+id/textView1"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="现在更新"
android:id="@+id/button2"
android:layout_below="@+id/textView1"
android:layout_toLeftOf="@+id/button1"/> </RelativeLayout>
Android布局管理器-从实例入手学习相对布局管理器的使用的更多相关文章
- 从实例中学习grid布局
对于Web开发者来说,网页布局一直是个比较重要的问题. Web 布局主要经历了以下四个阶段: 1.table表格布局: 2.float浮动及position定位布局: 3.flex弹性盒模型布局,革命 ...
- Android学习之电话拨号器
本人自己是做android驱动的,也会接触到系统层.上层的应用,所以在闲暇的时候也就开始了学习android应用的路程,在这里把这些东西记下来,希望自己能坚持下去,也好以后复习用. 今天先实现一个简单 ...
- java虚拟机学习-JVM内存管理:深入垃圾收集器与内存分配策略(4)
Java与C++之间有一堵由内存动态分配和垃圾收集技术所围成的高墙,墙外面的人想进去,墙里面的人却想出来. 概述: 说起垃圾收集(Garbage Collection,下文简称GC),大部分人都把这项 ...
- Expression Blend实例中文教程(11) - 视觉管理器快速入门Visual State Manager(VSM)
Expression Blend实例中文教程(11) - 视觉管理器快速入门Visual State Manager(V 时间:2010-04-12 16:06来源:SilverlightChina. ...
- android基础学习之布局
我学习android第一步接触的就是布局的学习.布局是androidUI的基础,是重中之重.总的来说android有6种布局,分别是线性布局LinearLayout.相对布局RelativeLayou ...
- android 学习 之 布局(上)
学习安卓布局前,先了解三个属性值: 1.fill_parent: 设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间 2.match_parent: And ...
- Android学习5—布局简介
Android界面的布局主要有四种,分别为RelativeLayout.LinearLayout.TableLayout.FrameLayout,接下来分别介绍这些布局如何使用(为了简单起见,接下来的 ...
- android 学习Layout布局的使用
android 常用布局 LinearLayout(线性布局) 线性的 垂直的 水平的RelativeLaytout(相对布局) 最灵活的TableLayout(表格布局) 使用GridView代替A ...
- Android自定义ViewGroup(四、打造自己的布局容器)
转载请标明出处: http://blog.csdn.net/xmxkf/article/details/51500304 本文出自:[openXu的博客] 目录: 简单实现水平排列效果 自定义Layo ...
随机推荐
- python+win32--com实现excel自动化
import win32com APP_TYPE = 'Excel.Application' xlBlack,xlRed,xlGray,xlBlue = 1,3,15,41 xlBreakFull ...
- NOI2.5 1490:A Knight's Journey
描述 Background The knight is getting bored of seeing the same black and white squares again and again ...
- SpringBoot与缓存
一.Spring Boot与缓存. JSR-107.Spring缓存抽象.整合Redis 一.JSR107 Java Caching定义了5个核心接口,分别是CachingProvider, Cach ...
- [CF1037F]Maximum Reduction
题意 https://codeforces.com/contest/1037/problem/F 思考 摘自一种比较有趣的做法.我们对序列进行分治,每次统计跨过mid的区间的贡献.其正确性是保证的:每 ...
- 基于django的会议室预订系统
会议室预订系统 一.目标及业务流程 期望效果: 业务流程: 用户注册 用户登录 预订会议室 退订会议室 选择日期:今日以及以后日期 二.表结构设计和生成 1.models.py(用户继承Abstrac ...
- Spring事务梳理
Spring事务传播行为 概述 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为 事务传播行为是Spring框架独有的事务增强特性,他不属于的事务实际提供方数 ...
- ThreadLocal梳理
ThreadLocal ThreadLocal提供了线程独有的局部变量,可以在整个线程存活的过程中随时取用,极大地方便了一些逻辑的实现. 当使用ThreadLocal维护变量时,ThreadLocal ...
- Spring-data-Jpa项目搭建
传送门:Spring Data 学习 Spring Data 开发环境搭建 Spring-data-jpa详解 简介 Spring Data是什么 Spring Data是一个用于简化数 ...
- SQL 两个时间段 不能重复语句
DECLARE @BeginDate datetime; DECLARE @EndDate datetime; set @BeginDate='2015-03-2' set @EndDate='201 ...
- supervisor守护filebeat服务进程
1.变更原因 部署安装supervisor进行filebeat守护及后面的各种服务进程守护可以用2.变更内容增加supervisor服务 3.变量时间:6月2号-6月3号4.变更风险评估:无风险4.1 ...