关于Android的布局

Android中五大布局是直接继承ViewGroup的布局:RelativeLayout、GridLayout、FrameLayout、AbsoluteLayout、LinnerLayout
(TableLayout是LinnerLayout的子类)

1、TableLayout 属于行和列形式的管理控件,每行为一个TableRow对象,也可以是一个View对象。
在TableRow中还可以继续添加其它的控件,每添加一个子控件就成为一列。(TableLayout不会生成边框。)
TableLayout重要的属性:
  collapseColumns:设置指定列为collapse,如果为collapse,该列被隐藏
  例: android:collapseColumns="0" 设置第一列隐藏,下标从0开始
  shrinkColumns:设置指定的列为shrinkable,如果为shrinkable,列的宽度进行收缩,自适应父容器的大小。
  例: android:shrinkColumns="1" 自适应
  stretchColumns:设置指定的列为stretchable,如果为stretchable,该列会被拉伸,填满表格的空白区域。
  例: android:stretchColumns="1" 第2列填满父控件

2、FrameLayout 帧布局中每一个组件都代表一个画面
  FrameLayout 的一个子类---TabHost很常用,可以实现导航页面

3、RelativeLayout布局
// 相对于给定ID控件
android:layout_above 将该控件的底部置于给定ID的控件之上;
android:layout_below 将该控件的底部置于给定ID的控件之下;
android:layout_toLeftOf 将该控件的右边缘与给定ID的控件左边缘对齐;
android:layout_toRightOf 将该控件的左边缘与给定ID的控件右边缘对齐;

android:layout_alignBaseline 将该控件的baseline与给定ID的baseline对齐;
android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;
android:layout_alignBottom 将该控件的底部边缘与给定ID的底部边缘对齐;
android:layout_alignLeft 将该控件的左边缘与给定ID的左边缘对齐;
android:layout_alignRight 将该控件的右边缘与给定ID的右边缘对齐;
// 相对于父组件
android:layout_alignParentTop 如果为true,将该控件的顶部与其父控件的顶部对齐;
android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;
android:layout_alignParentLeft 如果为true,将该控件的左部与其父控件的左部对齐;
android:layout_alignParentRight 如果为true,将该控件的右部与其父控件的右部对齐;
// 居中
android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;
android:layout_centerVertical 如果为true,将该控件的置于垂直居中;
android:layout_centerInParent 如果为true,将该控件的置于父控件的中央;
// 指定移动像素
android:layout_marginTop 上偏移的值;
android:layout_marginBottom 下偏移的值;
android:layout_marginLeft   左偏移的值;
android:layout_marginRight   右偏移的值;

4、GridLayout  网格布局

  重要属性:
  columnCount:列数
  rowCount:行数
  layout_rowSpan:合并行
  layout_columnSpan:合并列

5、LinnerLayout  线性布局
  特有属性:

  layout_weight:LinnerLayout特有属性,表示比重的意思,可实现百分百布局
  (如果控件为“match_parent”,则layout_weight的值与比重反相关,值越大,比重越小)

   android:orientation="vertical"  垂直排列

  android:orientation="horizontal"水平排列

6、AbsoluteLayout 绝对布局 一般不建议使用

原文地址:https://www.cnblogs.com/yangxiu/p/5899717.html