Android—Activity布局

  • Post author:
  • Post category:其他

一.LinearLayout

布局–是一个标签的树,每个标签就是View类的名字

设计模式:界面设计和应用程序逻辑分离的模式

1. 线性布局,其内元素线性排列。根据orientation属性可以设置排列方式:vertical是纵向排列,horizontal是横向排列。

2.几个重要属性:

(1)layout_width:宽,layout_height:高,二者均可以设置为:

    fill_parent:填满父控件

    wrap_content:包含内容即可

(2)gravity:控件中内容的位置

(3)layout_weight:比重(相对于同级控件而言)

(4)singleLine:是否强制内容显示在一行中,若设置为true,则过大的内容会以“…”来表示。

二.TableLayout

1.在TableLayout中,以<TableRow></TableRow>标签来表示表中的行,其中的控件每一个就是一列。

2.StretchColumns属性表示当一行中各列的宽度总和不能够填满屏幕时,指定某一列来拉伸填满。

三.RelativeLayout

1.相对布局,思想是一个控件的位置取决于与它周围空间的关系。

2.优点是灵活,缺点是很难掌握。

3.几个重要属性

(1)值为id的属性,引用名为:@id/id-name

——————————————————————————该控件与指定id控件的位置关系:至于某一控件的上/下/左/右。

layout_above

layout_below

layout_toLeftOf

layout_toRightOf

——————————————————————————该控件的某边缘与指定id控件的边线对齐。(水平方向对齐或者垂直方向对齐)

layout_alignBaseline

layout_alignBottom

layout_alignLeft

layout_alignRight

layout_alignTop

(2)值为Boolean的属性

——————————————————————————与父控件的某边线对齐,紧贴父元素的边线。

layout_alignParentLeft

layout_alignParentRight

layout_alignParentTop

layout_alignParentBottom

layout_alignWithParentTop If Missing  如果对应的兄弟元素找不到的话就以父元素做参照物

——————————————————————————控件的居中,

layout_centerHorizontal   水平居中

layout_centerVertical       垂直居中

layout_centerParent        相对于父元素居中

(3)值为具体的像素值,相邻控件之间的距离,离相邻控件某边缘的距离

layout_marginBottom

layout_marginTop

layout_marginLeft

layout_marginRight

四.关于xml文件的一点tips

1.注释:<!–   –>  快捷键 ctrl+shift+\

2.代码助手:alt+/

 

转载于:https://www.cnblogs.com/feiyue528/archive/2013/05/21/3091132.html