Relative Layout布局:相对位置布局,的几个重要属性 android
第一类 : 属性值为 true 或 false 布局
第二类:属性值必须为 id 的引用名“ @id/id-name ” spa
第三类:属性值为具体的像素值,如 30dip , 40px code
Relative Layout布局:相对位置布局,相似于Word中的位置对齐,总共有九个方位,以下图所示 xml
能够分别对应Word中的九个方位,以及还能够设置相似CSS中的组件与组件之间的外边距,如margin便是设置这一项,注意layout_margin这一项设置像素之后,则是设置的上下左右四个方位的值,若是只想设置某一边的话,则使用下面的marginLeft……之一,
设置组件内文字与组件边距可用属性padding,以下图: ip
下面,咱们来看看布局文件的代码与详解 utf-8
<?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="fill_parent" > <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:layout_below="@id/label" android:background="@android:drawable/editbox_background" /> <Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@id/entry" android:layout_marginLeft="10dip" android:text="OK" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/ok" android:layout_toLeftOf="@id/ok" android:text="Cancel" /> </RelativeLayout>
最后的效果图为: it
1.android:paddingLeft与android:layout_marginLeft的区别: io
padding margin都是边距的含义,关键问题得明白是什么相对什么的边距.
padding是控件的内容相对控件的边缘的边距.
layout_margin是控件边缘相对父空间的边距. class
2.android: gravity和android:layout_gravity区别
android:gravity 属性是对该view 内容的限定.好比一个button 上面的text. 你能够设置该text 在view的靠左,靠右等位置.该属性就干了这个.
android:layout_gravity是用来设置该view相对与起父view 的位置.好比一个button 在linearlayout里,你想把该button放在靠左靠右等位置就能够经过该属性设置.
这样就解释了,有什么咱们弄个最外布局,而后里面包了几个布局,若是要使这几个布局都靠底,就能够在最外布局的属性里设置androi:gravity="botton" 由于gravity是对里面的内容起做用.