android:layout_above 将该控件的底部至于给定ID的控件之上
android:layout_below 将该控件的顶部至于给定ID的控件之下
android:layout_toLeftOf 将该控件的右边缘和给定ID的控件的左边缘对齐
android:layout_toRightOf 将该控件的左边缘和给定ID的控件的右边缘对齐

android:layout_alignBaseline 该控件的baseline和给定ID的控件的baseline(基准线)对齐
android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘
android:layout_alignLeft 将该控件的左边缘与给定ID控件的左边缘对齐
android:layout_alignRight 将该控件的右边缘与给定ID控件的右边缘对齐
android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐

android:alignParentBottom 如果该值为true,则将该控件的底部和父控件的底部对齐
android:layout_alignParentLeft 如果该值为true,则将该控件的左边与父控件的左边对齐
android:layout_alignParentRight 如果该值为true,则将该控件的右边与父控件的右边对齐
android:layout_alignParentTop 如果该值为true,则将空间的顶部与父控件的顶部对齐

android:layout_centerHorizontal 如果值为真,该控件将被至于水平方向的中央
android:layout_centerInParent 如果值为真,该控件将被至于父控件水平方向和垂直方向的中央
android:layout_centerVertical 如果值为真,该控件将被至于垂直方向的中央

 import android.os.Bundle;
import android.widget.Button;
import android.app.Activity; public class Layout04 extends Activity {
private Button ok;
private Button cancel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ok = (Button)findViewById(R.id.ok);
cancel = (Button)findViewById(R.id.cancel); ok.setText(R.string.Ok);
cancel.setText(R.string.Cancel);
}
}
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10px" > <TextView android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:" /> <EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label" /> <Button android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10px"/> <Button android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">Layout04</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="Cancel">Cancel</string>
<string name="Ok">okk</string>
</resources>

RelativeLayout布局4.2几新特性:
android:layout_alignStart 表示将该控件放置在指定id控件的头部对齐
android:layout_alignEnd 表示将该控件放置在指定id控件的尾部对齐
android:layout_alignParentStart 如果为true,则将该控件放置在父控件的头部
android:layout_alignParentEnd 如果为true,则将该控件放置在父控件的尾部

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="@string/hello_world"
/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@id/view"
android:layout_below="@id/view"
android:text="hfasdrld"
/> </RelativeLayout>

EditText控件的两个属性:

android:hint="password" 设置EditText控件显示的文本
android:inputType="" 设置EditText控件输入的类型

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:id="@+id/myTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/TextView1" /> <EditText
android:id="@+id/uersname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@id/myTextView"
android:hint="uersname"
/> <EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/uersname"
android:layout_alignRight="@id/uersname"
android:layout_below="@id/uersname"
android:hint="password"
android:inputType="textPassword"
/> <Button
android:id="@+id/myButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/password"
android:text="@string/Button1"
/> <Button
android:id="@+id/myButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/myButton1"
android:layout_alignBottom="@+id/myButton1"
android:layout_toLeftOf="@+id/myButton1"
android:text="@string/Button2" /> </RelativeLayout>

控件布局_RelativeLayout的更多相关文章

  1. CSharpGL(26)在opengl中实现控件布局/渲染文字

    CSharpGL(26)在opengl中实现控件布局/渲染文字 效果图 如图所示,可以将文字.坐标轴固定在窗口的一角. 下载 CSharpGL已在GitHub开源,欢迎对OpenGL有兴趣的同学加入( ...

  2. React-Native 之控件布局

    Nodejs 一度将前端JS 推到了服务器端,而15年FB的React-Native RN再一次将JS 推到了移动端的开发浪潮中.RN的优势这里不再重复,它是我们这些习惯了服务端.web端开发,而又不 ...

  3. 运用 BoxLayout 进行 Swing 控件布局

    摘自http://www.cnblogs.com/fnlingnzb-learner/p/6008572.html 运用 BoxLayout 进行 Swing 控件布局 对于初学 Java Swing ...

  4. 学习笔记<4>初步控件布局

    一.控件布局基本概念 指控制控件在Activity当中的位置.大小.颜色以及其他控件样式属性 二.控件布局两种方法 1.使用布局文件完成控件布局(eclipse可视化拖拽控件实现) 2.在JAVA代码 ...

  5. 利用wtl的CDialogResize自动调整atl ActiveX控件布局

    前言 利用atl 开发activex控件时,如果使用atl复合控件时,acitvex控件上的界面元素不会自动改变大小,如果自己在OnSize中处理每个子控件的布局是一件非常麻烦的事,我们可以借助wtl ...

  6. QT学习记录之控件布局

    作者:朱金灿 来源:http://blog.csdn.net/clever101 想到控件布局就会想到Windows编程中要实现对话框上的控件的合理布局是一件多么艰难的事情.对此QT提出了一个很方便的 ...

  7. CPF 入门教程 - 控件布局(六)

    CPF netcore跨平台桌面UI框架 系列教程 CPF 入门教程(一) CPF 入门教程 - 数据绑定和命令绑定(二) CPF 入门教程 - 样式和动画(三) CPF 入门教程 - 绘图(四) C ...

  8. Android入门(六):Android控件布局属性全解

    第一类:属性值为true或falseandroid:layout_centerHrizontal 水平居中 (Hrizontal表示水平)android:layout_centerVertical 垂 ...

  9. Android:控件布局(表格布局)TableLayout

    TableLayout继承LinearLayout 实例:用表格布局实现计算机布局>>>>>>>>>>>> 有多少个TableR ...

随机推荐

  1. Ubuntu中root的默认密码

    原文地址:http://www.cnblogs.com/xuyingying/archive/2008/10/16/1312584.html 安装完Ubuntu后忽然意识到没有设 置root密码,不知 ...

  2. (转)eclipse上传项目到码云

    把Eclipse项目上传到码云的步骤: 1.登录码云:新建项目 2.输入项目名: 3.空项目创建成功如下图: 4.右键点击Eclipse的项目,选择“Team”—————->“Share Pro ...

  3. C#---初学ActiveMQ中间件

    本篇文章只适合跟我一样的初学者,因为现阶段的我们只想者怎么实现功能,不太会去考虑潜在异常.从上周开始优化公司的调控系统,原先采取的都是通过操作数据库去实现功能,客户体验效果不佳,经过领导决定是用中间件 ...

  4. 中国MOOC_面向对象程序设计——Java语言_第4章 继承与多态_第4周编程题_将MP3媒体类型存放进Database

    本周我们介绍了以继承方式实现的媒体资料库,在课程代码实现的基础上,请实现一个表达MP3的媒体类型,能和CD.DVD一样存放进这个Database.请提交这个MP3类的代码.如果你认为为了能存放MP3, ...

  5. 【作业一】Android开发环境以及开发前的准备

    对于Android平台的开发工具,我知道的就是Eclipse和Android Studio(后面简称AS).之前在学习JAVA时,渐渐习惯了Eclipse,后来要搭建Android的开发环境时,本来也 ...

  6. Python 线程同步变量,同步条件,列队

    条件变量同步 有一类线程需要满足条件之后才能够继续执行,Python提供了threading.Condition 对象用于条件变量线程的支持,它除了能提供RLock()或Lock()的方法外,还提供了 ...

  7. 【CSS学习】--- overflow属性

    一.前言 在网页布局中,未处理的溢出元素绝对算得上是个“毒瘤”.因为如果一个“盒子”周围还有其它元素,而从这个盒子中溢出的元素会和盒子周围的元素发生层叠,并脱离了整个HTML元素,所以我们应当合理使用 ...

  8. 【读书笔记】iOS-属性中的内存管理参数

    一,assign 代表设置时候直接赋值,而不是复制或者保留它. 二,retain. 会在赋值的时候把新值保留.此属性只能用于Object-C对象类型. 三,copy 在赋值时,将新值复制一份,复制工作 ...

  9. python之编码和解码

    编码: 1. ascii. 有: 数字, 字母, 特殊字符. 8bit 1byte 128 最前面是0 2. gbk. 包含: ascii, 中文(主要), 日文, 韩文, 繁体文字. 16bit, ...

  10. loadrunner 运行场景-场景运行原理

    运行场景-场景运行原理 by:授客 QQ:1033553122 运行原理 1 Remote Agent Dispatcher(Process) 运行Controller在负载机上开启应用程序. 2  ...