Android课程---布局管理器之相对布局(二)
这次示例代码是相对布局中兄弟组件之间,设置按钮的位置,难度:*****,一定要注意有同方向和反方向之分:
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课程---布局管理器之相对布局(二)的更多相关文章
- 三十三、Java图形化界面设计——布局管理器之null布局(空布局)
摘自http://blog.csdn.net/liujun13579/article/details/7774267 三十三.Java图形化界面设计--布局管理器之null布局(空布局) 一般容器都有 ...
- Android学习系列(二)布局管理器之线性布局的3种实现方式
转载请注明出处:http://blog.csdn.net/lhy_ycu/article/details/39643669 LinearLayout是Android控件中的线性布局控件,它包括的子控件 ...
- Java 图形编程 二:布局管理器之顺序布局
package second; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.Window ...
- 转:三十三、Java图形化界面设计——布局管理器之null布局(空布局)——即SWT中的绝对布局
http://blog.csdn.net/liujun13579/article/details/7774267 一般容器都有默认布局方式,但是有时候需要精确指定各个组建的大小和位置,就需要用到 ...
- Java图形化界面设计——布局管理器之null布局(空布局)
一般容器都有默认布局方式,但是有时候需要精确指定各个组建的大小和位置,就需要用到空布局. 操作方法: 1) 首先利用setLayout(null)语句将容器的布局设置为null布局(空布局 ...
- Android课程---布局管理器之相对布局(一)
下面示例的是在父容器里如何设置按钮的位置,难度:***,重点是找到一个主按钮,设置它的id,然后根据它来设置其他按钮在父容器的位置. 代码示例: <?xml version="1.0& ...
- Java 图形编程 二:布局管理器之边界布局
package second; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.Window ...
- 三十二、Java图形化界面设计——布局管理器之CardLayout(卡片布局)
摘自 http://blog.csdn.net/liujun13579/article/details/7773945 三十二.Java图形化界面设计--布局管理器之CardLayout(卡片布局) ...
- 三十一、Java图形化界面设计——布局管理器之GridLayout(网格布局)
摘自http://blog.csdn.net/liujun13579/article/details/7772491 三十一.Java图形化界面设计--布局管理器之GridLayout(网格布局) 网 ...
随机推荐
- poj1328 贪心
http://http://poj.org/problem?id=1328 神TM贪心. 不懂请自行搜博客. AC代码: #include<cstdio> #include<algo ...
- HDU5853 Jong Hyok and String(二分 + 后缀数组)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5853 Description Jong Hyok loves strings. One da ...
- C++可能出错的小细节
1. for(list<Geometry_line>::iterator it = G.begin(); it != G.end();) { if(IsLineCrossed(*it, l ...
- spark-sql访问hive的问题记录
好久没有弄博客了... hive0.14 spark0.12 [hadoop@irs bin]$ ./spark-sql Spark assembly has been built with Hive ...
- (转)HBase工程师线上工作经验总结----HBase常见问题及分析
阅读本文可以带着下面问题:1.HBase遇到问题,可以从几方面解决问题?2.HBase个别请求为什么很慢?你认为是什么原因?3.客户端读写请求为什么大量出错?该从哪方面来分析?4.大量服务端excep ...
- Shell 脚本
近期在别人的工作基础上完善了几个shell自动安装脚本. 1. 循环远程访问机器并安装 #!/bin/bash IpPrefix=. User=root Pwd= SMNIP=52.1.123.79 ...
- ajax与HTML5 history pushState/replaceState实例
一.本文就是个实例展示 三点: 我就TM想找个例子,知道如何个使用,使用语法什么的滚粗 跟搜索引擎搞基 自己备忘 精力总是有限的,昨天一冲动,在上海浦东外环之外订了个90米的房子,要借钱筹首付.贷款和 ...
- sqlite 数据类型 全面
http://blog.csdn.net/jin868/article/details/5961263 一般数据采用的固定的静态数据类型,而SQLite采用的是动态数据类型,会根据存入值自动判断.SQ ...
- Scheduled Projects
Plans as at 10/03/15 ASB --------> Li ...
- Codeforces Round #233 (Div. 2) B. Red and Blue Balls
#include <iostream> #include <string> using namespace std; int main(){ int n; cin >&g ...