这几天写布局属性关系一直很乱,所以百度加自己整理了一下Android四种常用控件的属性
Android.view.View和android.view.ViewGroup
android中的常见UI控件均会扩展View和ViewGroup其中有一部分是专门用来控制其子View位置和大小,这些类我们称为布局管理器。
ViewGroup
1.LayoutParams是ViewGroup内部类,包含了ViewGroup的布局参数,用来告诉它们的父类它们想怎么在父类中布局(大小和位置),所有在LayoutParams及其子类中定义的布局参数在xml中定义都是通过layout_***定义的。
LayoutParams只提供了两个参数设定:
layout_width 元素的高度(match_parent | wrap_content | *dip) layout_height 元素的宽度(
match_parent | wrap_content | *dip
)
2.MarginLayoutParams也是ViewGroup一个内部类,它继承了LayoutParams类,用来扩展LayoutParams的属性,设置参数。
MarginLayoutParams添加了四个参数设定:
layout_marginLeft 相对于本元素左边界的偏移
layout_marginRight 相对于本元素右边界的偏移
layout_marginTop, 相对于本元素上边界的偏移
layout_marginBottom 相对于本元素下边界的偏移
以上的两种Layout参数,所有布局中的子ViewGroup和子View都可以使用
下面讲述5种布局:
1.Linear Layout (线性布局)