Android 学习笔记6:布局管理器

来源:互联网 发布:2013软件设计师 编辑:程序博客网 时间:2024/06/07 12:05

Android常用的布局:

LinearLayout,RelativeLayout,TableLayout,FrameLayout,AbsoluteLayout

 

LinearLayout:

将多个View水平或垂直排列。注意:

如果是垂直排列,子控件的Layout_gravity设置为top,bottom等方向无效。

如果是垂直排列,子控件的Layout_gravity设置为right,left等方向无效

android:gravity    设置布局管理器内组件对其方式,如top,right,left,bottom,center,可以多个属性组合如top|right

android:orientation 设置组件的排列方式,包括 horizontal和vertical

控件间添加分割线

在低版本sdk中可以通过添加一个ImageView控件实现

高版本sdk,android:showDividers none beginning end middle 

android:divider :drawableID


TableLayout

添加<TableRow>就是添加一个表格行,向其中添加一个组件,就添加一列。不通过TableRow直接添加的组件占一行。

android:collapseColumns 设置需要被隐藏的列的序号,多个序号用,隔开

android:shrinkColumns 设置需要被收缩的列的序号,多个序号用,隔开

android:stretchColumns 设置需要被拉伸的列的序号,多个序号用,隔开

具体可以看http://blog.sina.com.cn/s/blog_63c66eb60100u29p.html


FrameLayout

整个屏幕当做一帧,每个组件占据一帧

无法设置组件在该帧中的位置,永远在左上角。

通过透明可以实现层叠效果

对于layout_margin的相关属性进行设置是无效的

android:foreground  设置前景图像

android:foregroundGravity 设置前景图形


RelativeLayout

组件位置相对父容器或兄弟组件进行布局


设置相相对父容器: 值只能是true或者false

android:layout_centerInParent  位于父控件的中间

android:layout_centerHorizontal 水平居中

android:layout_centerVertical  垂直居中

android:layout_alignParentLeft*4   靠(上/下/左/右)


设置相对于兄弟组件:后面的值是兄弟控件的id

android:layout_toRightof 位于兄弟控件的右边

android:layout_toLeftof位于兄弟控件的左边

android:layout_above  位于兄弟控件的上边

android:layout_below   位于兄弟控件的下边

android:layout_alignTop 和兄弟控件的上边界对齐

android:layout_alignBottom 和兄弟控件的下边界对齐

android:layout_alignLeft和兄弟控件的左边界对齐

android:layout_alignRight 和兄弟控件的右边界对齐 

  

AbsoluteLayout(最好不用)

布局容器不再管理组件的大小和位置,而是自己定义组件位置

layout_x

layout_y

 

0 0
原创粉丝点击