android的帧布局和表格布局

1.帧布局

特点:所有的元素都会置于视图的左上角,并且,后续元素会覆盖前面的元素。

layout代码实例:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent" >
 5 
 6     <TextView
 7         android:layout_gravity="center"              //上下左右居中
 8         android:id="@+id/textView1"
 9         android:layout_width="200dp"
10         android:layout_height="200dp"
11         android:text="第一个页面" 
12         android:background="#123456"/>
13 
14     <TextView
15         android:layout_gravity="center"
16         android:id="@+id/textView2"
17         android:layout_width="150dp"
18         android:layout_height="150dp"
19         android:text="第二个页面"
20         android:background="#321456" />
21 
22     <TextView
23         android:layout_gravity="center"
24         android:id="@+id/textView3"
25         android:layout_width="100dp"
26         android:layout_height="100dp"
27         android:text="第三个页面" 
28         android:background="#345254"/>
29 
30     <TextView
31         android:layout_gravity="center"
32         android:id="@+id/textView4"
33         android:layout_width="50dp"
34         android:layout_height="50dp"
35         android:text="第四个页面" 
36         android:background="#573452"/>
37 
38 </FrameLayout>

 

2.表格布局

TableLayout采用表格的形式管理控件,每一行为一个TableRow对象

1.全局属性

android:collapseColumns=“”                  ----列

android:shrinkColumns=“”                     -----排版收缩

android:  stretchColumns-“”                   ------排版扩张

 

2.局部属性

android:layout_columns=""                      ------显示在某列

android:layout_span=“ ”                         --------占用几列

3.实例

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 

    android:stretchColumns="*"                
    >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:layout_column="1"                               
            android:layout_span="2"                                 
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="3" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="4" />

        <Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="5" />

        <Button
            android:id="@+id/button6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="6" />

    </TableRow>

</TableLayout>

 

posted on 2017-04-19 16:04  码的艺术家  阅读(1019)  评论(0编辑  收藏  举报

导航