Android-相对布局(RelativeLayout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> 相对布局这里面到所有控件,都是有相对性的
1.相对与父控件
2.相对与和自己平级的控件 </RelativeLayout> 虽然相对布局需要对没有控件设置ID,才能使用,看起来LinearLayout方便写,实际上RelativeLayout更加对灵活,因为线性布局设置垂直或者水平就整版都是垂直与水平的,相对布局控制更加灵活写 相对布局,如果不指定ID,默认都是在左上角
相对bt_444控件中间线对齐:
android:layout_alignBaseline="@id/bt_333"
相对bt_444控件顶部对齐:
android:layout_alignTop="@id/bt_333"
相对bt_444控件的底部对齐:
android:layout_alignBottom="@id/bt_333"
<!--
相对于父控件系列: 相对于父控件垂直居中
android:layout_centerVertical="true" 相对于父控件水平居中
android:layout_centerHorizontal="true" 相对于父控件正中间
android:layout_centerInParent="true" 相对于父控件的右边
android:layout_alignParentRight="true" 相对于父控件的左边
android:layout_alignParentLeft="true" 相对于父控件的顶部
android:layout_alignParentTop="true" 相对于父控件的底部
android:layout_alignParentBottom="true" 相对于父控件的结束(通常情况下是在父控件最右边)
android:layout_alignParentEnd="true" 相对于父控件的开始 最左边 相对布局的默认
android:layout_alignParentStart="true" 相对于平级控件系列: 相对于bt_111控件的底部
android:layout_below="@+id/bt_111" 相对于bt_111控件的顶部
android:layout_above="@id/bt_111" 相对于bt_111控件的右边
android:layout_toRightOf="@id/bt_111" 相对于bt_111控件的左边
android:layout_toRightOf="@id/bt_111" 相对与控件的中间对齐
android:layout_alignBaseline="@id/bt_333" 相对与控件的顶部对齐
android:layout_alignTop="@id/bt_333" 相对与控件的底部对齐
android:layout_alignBottom="@id/bt_333" 相对与控件的中间对齐
android:layout_alignBaseline="@id/bt_333" 相对与控件的左对齐
android:layout_alignLife="@id/bt_333" 相对与控件的右对齐
android:layout_alignRight="@id/bt_333" // 外边距 上下左右 一般情况下用于 View
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
android:layout_marginRight="20dp"
android:layout_margin="20dp" 外边距往水平方向80dp
android:layout_marginHorizontal="80dp" 外边距往垂直方向80dp
android:layout_marginVertical="80dp" // 内边距 上下左右 一般情况下用于 ViewGroup 用来管控View
android:padding="40dp"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingTop="40dp"
android:paddingBottom="40dp" 内边距往水平方向60dp
android:paddingHorizontal="60dp" 内边距往垂直方向60dp
android:paddingVertical="60dp"
-->
相对布局测试的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <Button
android:id="@+id/bt_111"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1111" android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true" /> <Button
android:id="@+id/bt_222"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2222"
android:layout_toLeftOf="@id/bt_111"
android:layout_centerInParent="true"
/> <Button
android:id="@+id/bt_333"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:text="333"
android:layout_marginLeft="130dp"
android:layout_marginTop="130dp"
android:background="#f00"
/> <Button
android:id="@+id/bt_444"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="444"
android:layout_toRightOf="@id/bt_333"
android:layout_alignBaseline="@id/bt_333"
android:background="@color/colorAccent"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="555"
android:layout_alignParentStart="true"
/> </RelativeLayout>
Android-相对布局(RelativeLayout)的更多相关文章
- Android相对布局(RelativeLayout)
Android相对布局(RelativeLayout) 备注:这里的视图和元素是等同的概念. RelativeLayout是一个允许子视图相对于其他兄弟视图或是父视图显示的视图组(通过ID指定).每个 ...
- Android之布局RelativeLayout
线性布局的weight属性在等比例分配时比较方便,但是对复杂的界面,嵌套多层LinearLayout布局会导致渲染变慢,占用更多系统资源:而使用RelativeLayout的话,可能仅仅需要一层就可以 ...
- android的布局-----RelativeLayout(相对布局)
学习导图 注:父容器定位的属性值只能是Boolean ,兄弟组件定位的属性值只能是ID 典型案例(梅花) <?xml version="1.0" encoding=" ...
- Android UI -- 布局介绍(布局包括FrameLayout, LinearLayout, RelativeLayout, GridLayout)
首先介绍常用布局类 FrameLayout 最简单的布局管理器. 这个布局管理类有几个特性: 添加组件默认在左上角的. 如果添加多个组件会叠加到一起,并且都在左上角.(可以通过一gravity属性改变 ...
- Android 自学之相对布局 RelativeLayout
相对布局(RelativeLayout),相对布局容器内子组件的位置总是相对兄弟组件.父容器来决定的. RelativeLayout的XML属性及相关方法说明 XML属性 相关方法 说明 androi ...
- [Irving]Android 常用布局之RelativeLayout
RelativeLayout相对布局 相对布局 RelativeLayout 允许子元素指定它们相对于其父元素或兄弟元素的位置,这是实际布局中最常用的布局方式之一. 它灵活性大很多,当然属性也多,操作 ...
- 一步一步学android之布局管理器——RelativeLayout
今天开始学习RelativeLayout(相对布局),相对布局在平时布局的时候用的较多,因为Android适配方面的原因.相对布局可以控制组件摆放的位置(放在任一组件的上下左右等位置),下面来看看类的 ...
- Android 五大布局(LinearLayout、FrameLayout、AbsoulteLayout、RelativeLayout、TableLayout )
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...
- android LinearLayout和RelativeLayout实现精确布局
先明确几个概念的区别: padding margin:都是边距的含义,关键问题得明白是什么相对什么的边距padding:是控件的内容相对控件的边缘的边距. margin :是控件边缘相对父空间的边距 ...
- .Net程序猿玩转Android开发---(7)相对布局RelativeLayout
相对布局RelativeLayout是Android布局中一个比較经常使用的控件,使用该控件能够布局出适合各种屏幕分辨率的布局,RelativeLayout採用相对位置进行 ...
随机推荐
- python开发_function annotations
在看python的API的时候,发现了一个有趣的东东,即:python的方法(函数)注解(Function Annotation) 原文: 4.7.7. Function Annotations Fu ...
- mongodb(四)
Count+Distinct+Group数据库命令操作固定集合特性GridFS文件系统补充服务器端脚本 db.runCommand({group:{ ns:"persons", k ...
- myBaits association的使用
转自:https://blog.csdn.net/victor_cindy1/article/details/50194879 >
- 【源码阅读】Java集合之二 - LinkedList源码深度解读
Java 源码阅读的第一步是Collection框架源码,这也是面试基础中的基础: 针对Collection的源码阅读写一个系列的文章; 本文是第二篇LinkedList. ---@pdai JDK版 ...
- 跟我学算法聚类(DBSCAN)
DBSCAN 是一种基于密度的分类方法 若一个点的密度达到算法设定的阖值则其为核心点(即R领域内点的数量不小于minPts) 所以对于DBSCAN需要设定的参数为两个半径和minPts 我们以一个啤酒 ...
- 封装baseControl
package com.huawei.base; import java.io.IOException;import java.io.OutputStream;import java.io.Print ...
- Android开发实战之拥有Material Design风格的侧滑布局
在实现开发要求中,有需要会使用抽屉式布局,类似于QQ5.0的侧滑菜单,实现的方式有很多种,可以自定义控件,也可以使用第三方开源库. 同样的谷歌也推出了自己的侧滑组件——DrawLayout,使用方式也 ...
- Unity代码里的Position和界面上的Position
代码里的Position = 世界坐标 this.gameObject.transform.position 界面上的Position = localPosition
- SpringCloud04 服务配置中心、消息总线、远程配置动态刷新
1 环境说明 JDK:1.8 MAVENT:3.5 SpringBoot:2.0.5.RELEASE SpringCloud:Finchley.SR1 2 创建服务注册中心(Eureka服务端) 说明 ...
- Linux安装MySQL全过程
操作系统:CentOS 7.2 64位 mySQL版本:mysql-5.6.35 安装过程: (1)首先从mysql官网下载 MySQL Community Server 安装包. 选择对应的版本( ...