这次示例代码是相对布局中兄弟组件之间,设置按钮的位置,难度:*****,一定要注意有同方向和反方向之分:

1.同方向

1)layout_alignLeft 同方向左对齐

2)layout_alignRight 同方向右对齐

3)layout_alignTop 同方向顶部对齐

4)layout_alignBottom 同方向底部对齐

2.反方向

1)layout_above 在相对组件的上边
2)layout_below 在相对组件的下边
3)layout_toRightOf 在相对组件的右边
4) layout_toLeftOf 在相对组件的左边

注意:可以用相对的组件的id来设置

代码示例:

<?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"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
android:layout_centerInParent="true"
android:id="@+id/bt"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
android:layout_alignTop="@id/bt"
android:layout_toLeftOf="@+id/bt"
/><!--相对于第一个按钮即兄弟而言直接用"@id/bt"--> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
android:layout_alignLeft="@id/bt"
android:layout_above="@+id/bt"/>
<!--above在..之上,上面的顶边与下面的底边对齐反方向--> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
android:layout_alignLeft="@id/bt"
android:layout_below="@+id/bt"/>
<!--below 在..之下-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
android:layout_toRightOf="@id/bt"
android:layout_alignBottom="@+id/bt"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
android:layout_toRightOf="@id/bt"
android:layout_below="@+id/bt"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
android:layout_toRightOf="@id/bt"
android:layout_above="@+id/bt"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
android:layout_toLeftOf="@id/bt"
android:layout_below="@+id/bt"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"
android:layout_toLeftOf="@id/bt"
android:layout_above="@+id/bt"/> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="输入框"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:id="@+id/et"/><!--padding内边距-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:layout_alignParentRight="true"
android:layout_below="@+id/et"
android:id="@+id/ok"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cencel"
android:layout_below="@+id/et"
android:layout_toLeftOf="@+id/ok"
android:layout_marginRight="20dp"
/><!--margin外边距--> </RelativeLayout>

效果图:

Android课程---布局管理器之相对布局(二)的更多相关文章

  1. 三十三、Java图形化界面设计——布局管理器之null布局(空布局)

    摘自http://blog.csdn.net/liujun13579/article/details/7774267 三十三.Java图形化界面设计--布局管理器之null布局(空布局) 一般容器都有 ...

  2. Android学习系列(二)布局管理器之线性布局的3种实现方式

    转载请注明出处:http://blog.csdn.net/lhy_ycu/article/details/39643669 LinearLayout是Android控件中的线性布局控件,它包括的子控件 ...

  3. Java 图形编程 二:布局管理器之顺序布局

    package second; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.Window ...

  4. 转:三十三、Java图形化界面设计——布局管理器之null布局(空布局)——即SWT中的绝对布局

    http://blog.csdn.net/liujun13579/article/details/7774267    一般容器都有默认布局方式,但是有时候需要精确指定各个组建的大小和位置,就需要用到 ...

  5. Java图形化界面设计——布局管理器之null布局(空布局)

    一般容器都有默认布局方式,但是有时候需要精确指定各个组建的大小和位置,就需要用到空布局. 操作方法: 1)       首先利用setLayout(null)语句将容器的布局设置为null布局(空布局 ...

  6. Android课程---布局管理器之相对布局(一)

    下面示例的是在父容器里如何设置按钮的位置,难度:***,重点是找到一个主按钮,设置它的id,然后根据它来设置其他按钮在父容器的位置. 代码示例: <?xml version="1.0& ...

  7. Java 图形编程 二:布局管理器之边界布局

    package second; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.Window ...

  8. 三十二、Java图形化界面设计——布局管理器之CardLayout(卡片布局)

    摘自 http://blog.csdn.net/liujun13579/article/details/7773945 三十二.Java图形化界面设计--布局管理器之CardLayout(卡片布局) ...

  9. 三十一、Java图形化界面设计——布局管理器之GridLayout(网格布局)

    摘自http://blog.csdn.net/liujun13579/article/details/7772491 三十一.Java图形化界面设计--布局管理器之GridLayout(网格布局) 网 ...

随机推荐

  1. POJ 2201 Cartesian Tree ——笛卡尔树

    [题目分析] 构造一颗笛卡尔树,然后输出这棵树即可. 首先进行排序,然后用一个栈维护最右的树的节点信息,插入的时候按照第二关键字去找,找到之后插入,下面的树成为它的左子树即可. 然后插入分三种情况讨论 ...

  2. ios开发-载入viewcontroller的几种方式

    Assuming you have storyboard, go to storyboard and give your VC an identifier (inspector), then do: ...

  3. 贪心 Codeforces Round #287 (Div. 2) A. Amr and Music

    题目传送门 /* 贪心水题 */ #include <cstdio> #include <algorithm> #include <iostream> #inclu ...

  4. 【原】iOS学习之KVC原理

    1. KVC的实现原理 遍历字典里面所有的key,以name为例 去模型中查找有没有setName:方法,有就直接调用赋值 假如没有找到setName:方法,就会继续查找有没有_name属性,有就_n ...

  5. Leetcode Remove Nth Node From End of List

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  6. 求1+2+……+n(位运算)

    求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 我发现网上的做法都很神,各种理由编译的巧妙办法,就能间接 ...

  7. BZOJ2322: [BeiJing2011]梦想封印

    Description 渐渐地,Magic Land上的人们对那座岛屿上的各种现象有了深入的了解. 为了分析一种奇特的称为梦想封印(Fantasy Seal)的特技,需要引入如下的概念: 每一位魔法的 ...

  8. BZOJ3992: [SDOI2015]序列统计

    Description 小C有一个集合S,里面的元素都是小于M的非负整数.他用程序编写了一个数列生成器,可以生成一个长度为N的数列,数列中的每个数都属于集合S. 小C用这个生成器生成了许多这样的数列. ...

  9. DockerFile 参数详解

    Docker 指令: From --- ENV ---设置环境变量ENV App_DIR /appp Add 和 Copy 可以复制文件到容器里面 .区别 Add 可以写网络的链接地址 Add 支持解 ...

  10. 项目管理gitflow的用法(转)

    在这里主要讲一下我在项目中用到的关于gitflow的用法.   公司的项目中,专门有一台用来存放版本库的服务器,路径是在默认的安装目录/opt/git/,那么在使用的时候,如果你是一个功能模块或者是一 ...