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

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. Python学习笔记06

      源代码文件第一行添加:#coding:utf-8,这样就可以避免了 或者:#-*- coding: UTF-8 -*-   dict:实际就是哈希表,其键只能是不可变类型,如string,bool ...

  2. C#资源文件与与资源名称字符串之间的互相转化

    1.使用ResourceManager string st = Properties.Resources.ResourceManager.GetString(tableName);value = Pr ...

  3. AIM Tech Round 3 (Div. 2)

    #include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...

  4. What is classical music

    quanben's definition of classical music is a definition formed by the following aspects, 1. music wr ...

  5. Leetcode Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  6. Python拾忆--多线程的socket服务器

    阳光明媚的午后,想想最近要开始从写Java到写Python了,就随手打开电脑来体验一下Python与Java之间的不同吧~ 记得我还在上大二的时候,那个时候才开始学Java,最感兴趣的就是Java书最 ...

  7. tornado 学习笔记1 引言

    从事软件开发这行业也快5年啦,其实从事的工作也不完全是软件开发,软件开发只是我工作中的一部分.其中包括课题研究.信息化方案设计.软件开发.信息系统监理.项目管理等工作,比较杂乱.开发的软件比较多,但是 ...

  8. iOS模拟器多个虚拟机怎么处理

    1:关闭Xcode和模拟器 2:$sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService 等待输入密码 3:$rm -f ~/Libr ...

  9. 20145330第十周《Java学习笔记》

    20145330第十周<Java学习笔记> 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接收到指定的数据,这个就 ...

  10. 李洪强iOS经典面试题126

    1.#import和#include的区别,@class代表什么? @class一般用于头文件中需要声明该类的某个实例变量的时候用到,在m文件中还是需要使用#import 而#import比起#inc ...