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是用的最多的布局,也是最简单的布局。
顾名思义,其中的View都是按顺序排列的,而且只能是在一个方向上排列。
线性布局特有参数
android:orientation="vertical" 设置纵向线性
android:orientation="horizontal" 设置横向线性
android:layout_weight="1" 设置比重
示例:
<LinearLayout
...
android:orientation="horizontal">
<TextView
...
android:layout_weight="2"/>
<TextView
...
android:layout_weight="1"/>
</LinearLayout>
2.层布局 FrameLayout
FrameLayout是最厚的布局。
FrameLayout中添加的View都只能从左上角开始,然后一个一个叠加起来。说白了就是用来叠加其他布局用的。
FramLayout的布局用法最简单,把子节点放进去就ok了,没什么花样可玩。
FramLayout最值得研究的就是他的点击消息怎么传递的。
3.相对布局 RelativeLayout
RelativeLayout是最容易牵一发而动全身的布局。
每个View都是相对另一个View来确定位置,如果你要删除某个View,则很可能牵连其他的View。
相对布局特有参数
4.表格布局 TableLayout
TableLayout是最规矩的布局。
TableLayout其实就是在LinearLayout基础上进一步扩展,用LinearLayout合成一个横向+纵向的特有布局。
特有参数
android:collapseColumns="0,1"折叠
android:shrinkColumns="0,1" 收缩
android:stretchColumns="0,1" 拉伸
android:layout_span="3" 表示两个单元格合并
示例:
5.绝对布局 AbsoluteLayout
要写嘛!都是淘汰的产品了。