Android 五大布局-和整理的知识

    1. Android的中所有的可视化组件都是从VIew类派生而来的。通常把他们成为视图,视图也经常被称为控件或者小组件。

2.ViewGroup类是对View类的扩展,它是用来包含多个视图的。一般来说,视图组主要用于管理子试图的布局,但是也可以用来构建原子的可重用组件。

3.Android的五大布局---

android.widget.AbsoluteLayout 绝对布局

android.widget.RelativeLayout 相对布局

android.widget.LinearLayout 线性布局

android.widget.TableLayout 表格布局

android.widget.FrameLayout 层布局

如果给这五大布局使用频率做一个排序,应该如下

1.LinearLayout

2.FrameLayout

3.RelativeLayout

4.TableLayout 

5.AbsoluteLayout

程序中相关类

1.LinearLayout相关 LinearLayout类/LinearLayout.LayoutParams类

2.FramLayout相关 FramLayout类/FrameLayout.LayoutParams类

3.RelativeLayout相关 RelativeLayout类/RelativeLayout.LayoutParams类

4.TableLayout相关 TableLayout类/TableLayout.LayoutParams类/TableRow类/TableRow.LayoutParams类

5.AbsoluteLayout相关 都没人用还管它干嘛

1.线性布局 LinearLayout

LinearLayout按照垂直方向或者按照水平方向对齐每一个子视图。一个垂直方向的布局具有一个视图列,而一个水平方向的布局则有一个视图行。线性布局管理器允许为每一个子视图指定一个weight属性,以控制每一个子视图在可用空间内的相对大小。允许为每一个子视图指定一个weight属性,以控制每一个子视图在可用空间内的相对大小。

LinearLayout是用的最多的布局,也是最简单的布局。

顾名思义,其中的View都是按顺序排列的,而且只能是在一个方向上排列。

线性布局特有参数

android:orientation="vertical" 设置纵向线性

android:orientation="horizontal" 设置横向线性

android:layout_weight="1" 设置比重

示例:

  ...

 android:orientation="horizontal">

 

  ...

  android:layout_weight="2"/>

 

  ...

  android:layout_weight="1"/>



2.层布局 FrameLayout

FrameLayout是最厚的布局。

FrameLayout中添加的View都只能从左上角开始,然后一个一个叠加起来。说白了就是用来叠加其他布局用的。

FramLayout的布局用法最简单,把子节点放进去就ok了,没什么花样可玩。

FramLayout最值得研究的就是他的点击消息怎么传递的。


3.相对布局 RelativeLayout

RelativeLayout是最容易牵一发而动全身的布局。

每个View都是相对另一个View来确定位置,如果你要删除某个View,则很可能牵连其他的View。

相对布局特有参数

android:layout_toLeftOf
android:layout_toRightOf
android:layout_above
android:layout_below
android:layout_alignBaseline
android:layout_alignLeft
android:layout_alignRight
android:layout_alignTop
android:layout_alignBottom
android:layout_alignParentLeft
android:layout_alignParentRight
android:layout_alignParentTop
android:layout_alignParentBottom
android:layout_centerInParent
android:layout_centerHorizontal
android:layout_centerVertical
android:layout_margin
android:layout_marginLeft
android:layout_marginRight
android:layout_marginTop
android:layout_marginBottom
示例:
  ...
  android:background="#50124578">
    ...
  android:layout_centerInParent="true"/>
    ...
  android:layout_toRightOf="@id/textview1"
  android:layout_alignTop="@id/textview1"/>

注意:横向纵向都要设置参考值,否则就是默认值处理,默认左上对齐与Parent


4.表格布局 TableLayout

TableLayout是最规矩的布局。

TableLayout其实就是在LinearLayout基础上进一步扩展,用LinearLayout合成一个横向+纵向的特有布局。

特有参数

android:collapseColumns="0,1"折叠

android:shrinkColumns="0,1" 收缩

android:stretchColumns="0,1" 拉伸

android:layout_span="3" 表示两个单元格合并

示例:

  android:stretchColumns="0,1">
 
          android:layout_span="3"/>
    
 

 
   
    
 


还有很多可研究的地方,用的不多就不研究了

5.绝对布局 AbsoluteLayout

要写嘛!都是淘汰的产品了。

 

你可能感兴趣的:(Android)