您的位置:首页 > 移动开发 > Android开发

android布局属性具体解释

2016-03-08 09:09 507 查看
RelativeLayout用到的一些重要的属性:

1:LinearLayout ( 线性布局 ) (里面仅仅能够有一个控件,而且不能设计这个控件的位置,控件会放到左上角)

线性布局分为水平线性和垂直线性二者的属性分别为: android:orientation= " horizontal " android:orientation= "vertical" 。

2:RelativeLayout ( 相对布局 ) : (里面能够放多个控件,可是一行仅仅能放一个控件)

第一类 : 属性值为 true 或 false

android:layout_centerHorizontal 水平居中

android:layout_centerVertical 垂直居中

android:layout_centerInparent 相对于父元素全然居中

android:layout_alignParentBottom 贴紧父元素的下边缘

android:layout_alignParentLeft 贴紧父元素的左边缘

android:layout_alignParentRight 贴紧父元素的右边缘

android:layout_alignParentTop 贴紧父元素的上边缘

android:layout_alignWithParentIfMissing 若找不到兄弟元素以父元素做參照物

第二类:属性值必须为 id 的引用名“ @id/id-name ”

android:layout_below 在某元素的下方

android:layout_above 在某元素的上方

android:layout_toLeftOf 在某元素的左边

android:layout_toRightOf 在某元素的右边

android:layout_alignTop 本元素的上边缘和某元素的的上边缘对齐

android:layout_alignLeft 本元素的左边缘和某元素的的左边缘对齐

android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐

android:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐

第三类:属性值为详细的像素值,如 30dip , 40px

android:layout_marginBottom 离某元素底边缘的距离

android:layout_marginLeft 离某元素左边缘的距离

android:layout_marginRight 离某元素右边缘的距离

android:layout_marginTop 离某元素上边缘的距离

3:TableLayout ( 表格布局 ) : (这个要和TableRow配合使用,非常像html里面的table)

这个表格布局不像HTML中的表格那样灵活,仅仅能通过 TableRow 属性来控制它的行而列的话里面有几个控件就是几列(普通情况)。 如:

<TableLayout>

 <TableRow>

  <EditText></EditText>

  <EditText></EditText>

 </TableRow>

 <TableRow>

  <EditText></EditText>

  <EditText></EditText>

 </TableRow>

</TableLayout>

表示两行两列的一个表格。

android:gravity="center" 书面解释是权重比。其时就是让它居中显示。

它还能够动态加入里面的每行每列。例如以下代码所看到的:

  /*依据id查找表格对象*/

  TableLayout tableLayout = (TableLayout) findViewById(R.id.table01);

  /*创建列对象*/

  TableRow tableRow = new TableRow(this);

  /*文本框对象*/

  TextView temp = new TextView(this);

  temp.setText("text的值");

  /*将此文本加入到列中*/

  tableRow.addView(temp);

  android:stretchColumns="1,2,3,4" 它的意思就是自己主动拉伸1,2,3,4列。

4:AbsoluteLayout ( 绝对布局 ) : (里面能够放多个控件,而且能够自定义控件的x,y的位置)

5:FrameLayout ( 帧布局 ) :(里面能够放多个控件,只是控件的位置都是相对位置)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: