相对布局(RalativeLayout)

是指相对于其他部件或者父部件的布局方式。

1、相对于容器定位:

  android:layout_alignParentTop 将部件的顶部与容器的顶部对齐。

  android:layout_alignParentBottom

  android:layout_alignParentLeft

  android:layout_alignParentRight

  android:layout_centerHorizontal 将部件放在容器的垂直居中

  android:layout_centerVertical 水平居中

  android:layout_centerInParent 水平和垂直居中

    【这些属性的值都是一个布尔值true false】

2、关联记号 1)、@+id/为所有的元素的添加id 2)、@id/ 用来引用其他部件 【例】部件A @+id/widget_a,那么另外一个部件B可以通过标示符@id/widget_a引用该部件。

3、相对其他部件的位置。。

android:layout_above

android:layout_below 在一个一个部件的下面

android:layout_toLeftOf

android:layout_toRightOf

和其他部件的对齐方式

android:layout_alignTop是该部件与被引用的部件顶端对齐

android:layout_alignBottom

android:layout_alignRight 右边对齐

android:layout_alignLeft

android:layou_alignBaseline 两个部件相对于基线对齐 所谓基线就是文本恰好位于其上的一条看不见的线。

<一段XML文件,显示使用方法>

<?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 = "5px" >    <TextView        android:id = "@+id/label"        android:layout_width = "wrap_content"        android:layout_height = "wrap_content"        android:text = "URL:"        android:padding = "15px"/>    <EditText        android:id = "@+id/entry"        android:layout_width = "fill_parent"        android:layout_height = "wrap_content"        android:layout_toRightOf = "@id/label"        android:layout_alignBaseline = "@id/label"        />    <Button        android:id = "@+id/ok"        android:layout_width = "wrap_content"        android:layout_height = "wrap_content"        android:layout_below = "@id/entry"        android:layout_alignRight = "@id/entry"        android:text = "OK"         />    <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"        android:layout_alignBottom = "@id/ok"        android:text= "Cancel"        />              </RelativeLayout>
View Code

更多相关文章

  1. Android去除EditText的聚焦Focuse
  2. Android控件的高度,宽度设置
  3. android精确绘制文字位置的方法
  4. Andoid - 开发实例(3):高仿微信的界面
  5. Android布局管理器浅析
  6. 安卓开发学习之002 LinearLayout之android:layout_gravity详解
  7. android應用what to test?
  8. android桌面小部件appwidget使用ListView或者StackView如何刷新
  9. iScroll框架解析——Android(安卓)设备页面内 div(容器,非页面)over

随机推荐

  1. android进程在管理器中被杀死
  2. Android(安卓)高手进阶教程(十四)之----A
  3. Android(安卓)开发中Parcel存储类型和数
  4. Android(安卓)学习
  5. android - 为安全而设计 - 1 - 开发文档
  6. android mediastore
  7. Kotlin语言 Android与JS交互
  8. Android(安卓)内存详细分析
  9. 转: Android基于HLS和RTMP协议的第三方SD
  10. 关于openGL, openGL ES, openVG及android