相对布局管理器指的是參考某一其它控件进行摆放,能够通过控制,将组件摆放在一个指定參考组件的上、下、左、右等位置,这些能够直接通过各个组件提供的属性完毕。
以下介绍一下各个方法的基本使用
No.
属性名称
相应的规则常量
描写叙述
1
android:layout_below
RelativeLayout.BELOW
摆放在指定组件的下边
2
android:layout_toLeftOf
RelativeLayout.LEFT_OF
摆放在指定组件的左边
3
android:layout_toRightOf
RelativeLayout.RIGHT_OF
摆放在指定组件的右边
4
android:layout_alignTop
RelativeLayout.ALIGN_TOP
以指定组件为參考进行上对齐
5
android:layout_alignBottom
RelativeLayout.ALIGN_BOTTOM
以指定组件为參考进行下对齐
6
android:layout_alignLeft
RelativeLayout.ALIGN_LEFT
以指定组件为參考进行左对齐
7
android:layout_alignRight
RelativeLayout.ALIGN_RIGHT
以指定组件为參考进行右对齐

<span style="font-size:18px;"><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"
android:textAlignment="center"
tools:context=".MainActivity" > <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10" /> <EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText1"
android:layout_below="@+id/editText1"
android:ems="10"
android:inputType="textPassword" > <requestFocus />
</EditText> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentLeft="true"
android:text="账号" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="password"
android:textAlignment="center" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_marginLeft="23dp"
android:layout_marginTop="36dp"
android:layout_toRightOf="@+id/textView2"
android:text="登 录" /> <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_marginLeft="14dp"
android:layout_toRightOf="@+id/button1"
android:autoLink="web"
android:linksClickable="true"
android:text="忘记password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="10dp" /> </RelativeLayout>
</span>



使用相对布局是眼下基本的布局方式,它比其它方式都方便快捷,能够再可视化界面直接拖拽就可以。

…………………………………………………………毫无美感的切割线…………………………………………………………
使用动态表布局实现和前面的是一样的,不常使用在这里不再赘述,有兴趣的读者能够自己尝试。
须要使用下面几个方法。
1
public RelativeLayout.LayoutParams (int w, int h)
构造
指定RelativeLayout布局的宽度和高度
2
public void addRule (int verb, int anchor)
普通
添加指定的參数规则
3
public int[] getRules ()
普通
取得一个组件的所有參数规则



下节预报:使用嵌套布局实现计算器界面


从零開始学android&lt;RelativeLayout相对布局.十六.&gt;的更多相关文章

  1. 从零開始学android&lt;使用嵌套布局实现计算器界面.十七.&gt;

    所谓的嵌套布局就是在一个文件里嵌套多个布局文件 <span style="font-size:18px;"> <LinearLayout android:layo ...

  2. 从零開始学android&lt;ScrollView滚动视图.十八.&gt;

    因为手机屏幕的高度有限.所以假设面对组件要显示多组信息的时候,ScrollView视图(滚动视图)能够有效的安排这些组件,浏览时能够自己主动的进行滚屏的操作. android.widget.Scrol ...

  3. 第13章、布局Layouts之RelativeLayout相对布局(从零開始学Android)

    RelativeLayout相对布局 RelativeLayout是一种相对布局,控件的位置是依照相对位置来计算的,后一个控件在什么位置依赖于前一个控件的基本位置,是布局最经常使用,也是最灵活的一种布 ...

  4. 从零開始学android&lt;数据存储(1)SharedPreferences属性文件.三十五.&gt;

    在android中有五种保存数据的方法.各自是: Shared Preferences Store private primitive data in key-value pairs. 相应属性的键值 ...

  5. 从零開始学android&lt;SeekBar滑动组件.二十二.&gt;

    拖动条能够由用户自己进行手工的调节,比如:当用户须要调整播放器音量或者是电影的播放进度时都会使用到拖动条,SeekBar类的定义结构例如以下所看到的: java.lang.Object    ↳ an ...

  6. 从零開始学android&lt;mediaplayer自带播放器(视频播放).四十九.&gt;

    MediaPlayer除了能够对音频播放之外,也能够对视频进行播放,可是假设要播放视频仅仅依靠MediaPlayer还是不够的.还须要编写一个能够用于视频显示的空间,而这块显示空间要求能够高速的进行G ...

  7. 从零開始学android&lt;TabHost标签组件.二十九.&gt;

    TabHost主要特点是能够在一个窗体中显示多组标签栏的内容,在Android系统之中每一个标签栏就称为一个Tab.而包括这多个标签栏的容器就将其称为TabHost.TabHost类的继承结构例如以下 ...

  8. 从零開始学android&lt;ImageSwitcher图片切换组件.二十六.&gt;

    ImageSwitcher组件的主要功能是完毕图片的切换显示,比如用户在进行图片浏览的时候.能够通过button点击一张张的切换显示的图片,并且使用ImageSwitcher组件在每次切换的时候也能够 ...

  9. 从零開始学android&lt;AnalogClock与DigitalClock时钟组件.三十一.&gt;

    这两个组件比較交单,大家看下会使用即可了 XML文件配置 <span style="font-size:18px;"><RelativeLayout xmlns: ...

随机推荐

  1. 自己定义UITabBarController

    网上大多的自己定义TabBar都是继承View的,项目中要用到path+Tabbat这种话(path用的MMDrawerController这个框架),继承View的Tabbar是无法满足条件的(不是 ...

  2. uva 10602 Editor Nottoobad(排序)

    题目连接:10602 Editor Nottoobad 题目大意:要输入n个单词,现在有三种操作, 1.输入一个字符,需要按下一次按键.  2.通过声控删除一个字符.3.通过声控复制一遍上面的单词.现 ...

  3. android在假设绘制自己定义的bitmap,然后返回给ImageView

    先来说一下FontMetrics这个类.这个类是关于字符属性和測量的类 用图能够更精确的知道各个属性的含义: 我们在Layout中有一个ImageView,我们能够通过: <span style ...

  4. Common Lisp第三方库介绍 | (R "think-of-lisper" 'Albertlee)

    Common Lisp第三方库介绍 | (R "think-of-lisper" 'Albertlee) Common Lisp第三方库介绍 一个丰富且高质量的开发库集合,对于实际 ...

  5. table明明设置了固定值

    IE真的快把我搞死了 0.0 可爱的迷人的让人醉了的IE你真棒 今天用表格写一个4列的表格 要实现的效果大概是这种 确有用普通浏览器都没有问题 非常easy明了的一个表格嘛!用IE8下面的看就成这样子 ...

  6. Modular Fibonacci

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=30506#problem/U fib数列对2^m取模的循环节为3*(2^(m-1)) #i ...

  7. HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)

    50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...

  8. linux下的开源移动图像监测程序--motion编译与配置

    前几天在网上偶然看到一篇博客,是利用linxu下的开源的motion搭建嵌入式视频动态监控系统,感觉很好很强大于,是就想自己编译移植一下试试. 所谓移动图像监测,简单来说就是利用摄像头定点监测某个区域 ...

  9. Android中&lt;meta-data&gt;的使用

    在AndroidManifest.xml中.<meta-data>元素能够作为子元素,被包括在<activity>.<application> .<servi ...

  10. Android----------WindowManager

    我们Android平台是一个又一个的Activity组成的,每个Activity有一个或者多个View构成.所以说.当我们想显示一个界面的时候,我们首先想到的是建立一个Activity,然后全部的操作 ...