Android布局是所有带界面的Android应用的开端,布局应用的好坏直接决定了用户体验。


Android共有五种布局,分别为FrameLayout(堆栈布局)、 LinearLayout(线性布局)、 RelativeLayout(相对布局)、 TableLayout(表格布局)、 AbsoluteLayout(绝对布局)。最常用的布局是FrameLayout、LinearLayout和RelativeLayout。


FrameLayout:在布局文件中使用<FrameLayout>标签标示。FrameLayout布局中的View都会以层叠方式显示,类似于Photoshop的图层。放在最后的View会显示在最上层,因此,可将FrameLayout称为堆栈布局。

LinearLayout:可将多个View水平或垂直排列。如果android:orientation属性的值为horizontal,View会水平排列,属性值为vertical,View会垂直排列。horizontal是android:orientation属性的默认值。

RelativeLayout:可以通过确定两个或多个组件的相对位置来摆放组件。与组件相对位置相关饿属性包括android:layout_toLeftOf(将当前组件置于该属性指定组件的左侧)、android:layout_toRightOf(将当前组件置于该属性指定组件的右侧)、android:layout_below(将当前组件置于该属性指定组件的下方)、android:layout_above(将当前组件置于该属性指定组件的上方)。这4个属性值必须指定已经存在的ID。

TableLayout布局可以将View按表格形式排列。

AbsoluteLayout可以设置View的绝对坐标,但不建议使用AbsoluteLayout设计界面,因为该布局无法适应屏幕分辨率的变化。


常用的布局属性:

android:id:控件指定相应ID。

android:text:控件中显示文字,尽量使用Strings.xml。

android:gravity:控件中文字基本位置,如center、left、right、center_horizontal等。

android:textsize:控件中字体大小,单位为pt。

android:background:控件背景色。

android:width:控件宽度。

android:height:控件高度。

android:padding:控件内边距。

android:siglelise:为true,则控件内容将在同一行显示。

android:margin:外边距。


android:layout_centerHrizontal 是否至于水平方向中央

android:layout_centerVertical 是否至于垂直方向中央

android:layout_centerInparent 至于父控件水平/垂直方向中央

android:layout_alignParentBottom 是否与父控件下边对齐

android:layout_alignParentLeft 是否与父控件的左边对齐

android:layout_alignParentRight 是否与父控件的右边对齐

android:layout_alignParentTop 是否与父控件的上边对齐

android:layout_alignWithParentIfMissing


android:layout_below 在某某上面

android:layout_above 在某某下面

android:layout_toLeftOf 将控件左边缘至于给定控件的右边

android:layout_toRightOf 将控件右边缘至于给定控件的左边

android:layout_alignTop 将控件的顶部与给定控件顶部对齐


android:layout_marginBottom 与下边的距离

android:layout_marginLeft 与左边的距离

android:layout_marginRight 与右边的距离

android:layout_marginTop 与上边的距离


更多相关文章

  1. Android(安卓)之 CheckBox 详解
  2. Android之ListView中的分割线和行高
  3. Android的CheckBox控件的点击效果布局文件
  4. android自定义滚动条(ScrollBar)样式
  5. Android(安卓)XML属性在文档中的位置
  6. android 中的 edittext属性大全
  7. Android(安卓)SDK 安装中组件的离线安装方法 (share)
  8. Android学习笔记:androidmanifest.xml 高级属性
  9. android 拨号盘Contact模块讲解(四)

随机推荐

  1. android 使用数据库事务提高操作效率
  2. Android工具包
  3. springmvc服务端+android客户端的文件上
  4. adb连接不上模拟器的问题
  5. Android中获取SQL Server中的数据
  6. android 音效
  7. android添加各种权限整理
  8. 【OOM】Android加载大图片OOM异常解决
  9. Android腾讯微薄客户端开发十四:首页menu
  10. android ScrollView--Linearlayout可以上