xml布局文件基本属性

 

android:layout_above 将该控件置于给定ID的控件之上。
android:layout_below 将该控件置于给定ID的控件之下。
android:layout_toLeftOf 将该控件置于给定ID的控件之左。
android:layout_toRightOf 将该控件置于给定ID的控件之右。
例:android:layout_above=”@id/XXX”
这组属性的后面跟的都是相对控件的ID,表示的都是相对给定ID控件的上下左右方向位置。

 

android:layout_alignBaseline
android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘对齐
android:layout_alignLeft 将该控件的左边边缘与给定ID控件的左边边缘对齐
android:layout_alignTop 将该控件的顶部边缘与给定ID控件的顶部边缘对齐
android:layout_alignRight 将该控件的右边边缘与给定ID控件的右边边缘对齐
例:android:layout_alignBotton=”@id/XXX”
这组属性的后面跟的都是相对控件的ID,表示的都是控件自身的上下左右边缘与给定ID控件的对应边缘对齐。外对齐。

 

android:layout_alignParentBottom 如果值为true,则将该控件的底部与父控件的底部对齐
android:layout_alignParentLeft 如果值为true,则将该控件的左边缘与父控件的左边缘对齐
android:layout_alignParentRight如果值为true,则将该控件的右边缘与父控件的右边缘对齐
android:layout_alignParentTop如果值为true,则将该控件的顶部与父控件的顶部对齐
例:android:layout_alignParentBottom = true
这组属性的后面跟的是true或false,如果不指定,默认就是false,表示的都是控件自身的上下左右边缘与父控件的对应边缘对齐,因为控件是在父控件的内部,所以是内对齐。

 

android:layout_centerHorizontal 如果值为true,则该控件在其父控件范围内水平居中
android:layout_centerInparent 如果值为true,则该控件在
其父控件范围内垂直且水平居中
android:layout_centerVertical如果值为true,则该控件在
其父控件范围内垂直居中
例:android:layout_centerHorizontal = true
这组属性的后面跟的是true或false,如果不指定,默认就是false,表示的都是控件自身相对于父控件范围内的居中情况。

horizontally水平地 vertically垂直地


android:layout_marginBottom="3dip"则该控件距离其父控件底部3dip
        android:layout_marginLeft="30dip"
则该控件距离其父控件左部30dip
        android:layout_marginRight="3dip"
则该控件距离其父控件右部3dip
        android:layout_marginTop="3dip"
则该控件距离其父控件顶部3dip

当按钮分别设置以上两个属性时,得到的效果是不一样的。

android:paddingLeft="30px"

按钮上设置的内容(例如图片)离按钮本身左边边界30个像素

android:layout_marginLeft="30px"

整个按钮离其父控件左边设置的内容30个像素


android:gravity  
android:gravity属性是对该view 内容的限定.比如一个button 上面的text.  你可以设置该text 在view的靠左,靠右等位置.以button为例,android:gravity="right"则button上面的文字靠右 

android:layout_gravity 
android:layout_gravity是用来设置该view相对与其父view 的位置.比如一个button 在linearlayout里,你想把该button放在靠左、靠右等位置就可以通过该属性设置.以button为例,android:layout_gravity="right"则button靠右


[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent">  
  5.     <TextView  
  6.         android:id="@+id/label"  
  7.         android:layout_width="fill_parent"  
  8.         android:layout_height="wrap_content"  
  9.         android:text="Type here:"/>  
  10.     <EditText  
  11.         android:id="@+id/entry"  
  12.         android:layout_width="fill_parent"  
  13.         android:layout_height="wrap_content"  
  14.         android:background="@android:drawable/editbox_background"  
  15.         android:layout_below="@id/label"/>  
  16.     <Button  
  17.         android:id="@+id/ok"  
  18.         android:layout_width="wrap_content"  
  19.         android:layout_height="wrap_content"  
  20.         android:layout_below="@id/entry"  
  21.         android:layout_alignParentRight="true"  
  22.         android:layout_marginLeft="10dip"  
  23.         android:text="OK" />  
  24.     <Button  
  25.         android:layout_width="wrap_content"  
  26.         android:layout_height="wrap_content"  
  27.         android:layout_toLeftOf="@id/ok"  
  28.         android:layout_alignTop="@id/ok"  
  29.         android:text="Cancel" />  
  30. RelativeLayout> 
总之一句话:带layout的是向外即此控件距离其父控件的距离,而不带layout的是向内此控件内部的数据设定。

更多相关文章

  1. 线性布局控件间的布局设置
  2. 关于android的animation的xml定义中的android:interpolator属性
  3. android的布局属性(转)
  4. padding和margin的区别及其属性
  5. Android 的属性系统
  6. [Android] EditText 的 inputType属性(键盘类型)
  7. Android中TextVIew一些属性
  8. Android EditText控件

随机推荐

  1. Android studio 自定义打包APK名称
  2. Android中ActivityManager学习笔记(3)
  3. Android学习笔记-1.Android工程结构
  4. android暂停或停止其他音乐播放器的播放
  5. Android的四种启动模式(launchModel)
  6. 【搜集】Android permission 访问权限(附
  7. 【Android Studio问题】创建模拟器时没有
  8. Android Studio 3.5 JNI (ndk-build)
  9. android studio 安装模拟器报错 intel HA
  10. Android studio创建android项目学习(一)