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 ...
随机推荐
- Knative 简介
原文地址:https://yq.aliyun.com/articles/658800
- centos7的新特性
1.修改主机名方式改变 centos6在/etc/ centos7使用命令hostnamectl set-hostname 主机名2.修改时间方式改变3.查看IP地址ifconfig不再支持改用ip4 ...
- 大叔 Frameworks.Entity.Core 3 Predicate
Frameworks.Entity.Core\Commons\Predicate\ 1LinqEntity.cs /// IQueryable扩展方法:条件过滤与排序功能 /// Modify ...
- JS-08-对象
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- qt creator源码全方面分析(0)
本人主攻C++和Qt. 上两天刚研究完Qt install framework(IFW)应用程序安装框架. google没发现有正儿八经的官方文档的翻译,我就进行了翻译哈!! 系列文章具体见:http ...
- java 排序算法分析
一.冒泡排序(时间复杂度O(N^2)) public int[] bubbling(int[] arr){ ) return arr; ; i--){ 1 ; j < i-; j ++){ 2 ...
- Linux学习笔记-配置阿里云yum源
进入目录:cd /etc/yum.repos.d 备份:mkdir repobak mv *.repo repobak/ 下载CentOS-Base.repo 到路径/etc/yum.repos.d/ ...
- 用Java实现一个简单的DBMS(总结)
时间:2020/1/16 写这个DBMS(说DBMS夸张了,应该是一个控制台程序)的起因是数据库实践老师布置的一个大作业,先贴上GitHub地址: https://github.com/machi12 ...
- top100tools
Top 100 Tools for Learning 2013 2142 EmailShare Here are the Top 100 Tools for Learning 2013 – the ...
- [apue] 书中关于伪终端的一个纰漏
在看 apue 第 19 章伪终端第 6 节使用 pty 程序时,发现“检查长时间运行程序的输出”这一部分内容的实际运行结果,与书上所说有出入. 于是展开一番研究,最终发现是书上讲的有问题,现在摘出来 ...