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

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. H5危险的文件上传对话框

    文件对话框 文件上传对话框是一直以来就存在的网页控件. 到了 HTML5 时代,增加了更多的功能,例如支持文件多选.Chrome 甚至还支持「上传文件夹」这一私有特征: <input type= ...

  2. 移动Web开发规范

    1.字体设置 使用无衬线字体 body { font-family: "Helvetica Neue", Helvetica, STHeiTi, sans-serif; } 2.设 ...

  3. Java ClassLoader基础及加载不同依赖 Jar 中的公共类

    转载自:最新内容及最清晰格式请见 http://www.trinea.cn/android/java-loader-common-class/ 本文主要介绍 ClassLoader 的基础知识,Cla ...

  4. poj 1321 棋盘问题

    八皇后问题变形,回溯法. #include <cstdio> #include <cstring> #include <iostream> using namesp ...

  5. DSP using Matlab 示例Example2.2

    a. n = -2:10; x = [1:7,6:-1:1]; % generate x(n) [x11,n11] = sigshift(x,n,5); [x12,n12] = sigshift(x, ...

  6. node.js整理 01代码的组织和部署

    模块 require(函数) 用于在当前模块中加载和使用别的模块,传入一个模块名,返回一个模块导出对象. 模块名可使用相对路径(以./开头),或者是绝对路径(以/或C:之类的盘符开头:注意单个模块名默 ...

  7. wpf ListBox,item两列不等高。

    业务有这样的需求,类似瀑布流.内容两列不等高展示. 只需要继承panel,重写MeasureOverride和ArrangeOverride方法就行了. 很简单,内容都在代码里. using Syst ...

  8. 通过adb命令打印log

    1.adb logcat  --打印当前设备上所有日志 2.adb logcat | findstr *** --过滤仅含***的日志 3.adb logcat *:W  --过滤打印严重级别W及以上 ...

  9. 相遇点对 & 数点问题

    题意: 一个长为l的环,环上有n个点,每个点以一定的速度顺时针或逆时针运动,两个点相遇即某一时刻内两个点位置相同. 求有多少点对相遇----相同点对出现多次仅统计一次. SOL: 考试的时候想到用线段 ...

  10. IE下margin:0 auto为什么不居中?

    http://blog.sina.com.cn/s/blog_68c6be330101k7kn.html 我们经常用DIV+CSS布局网页的时候,正常情况下需要将div居中显示时,使用Css样式:ma ...