Android 应用软件开发(六)窗口布局

窗口的布局是在layout中的.xml文件中实现的

一般可以使用eclipse的代码提示功能 Alt+/来显示后面要加的属性值

首先看一下线性布局式样:LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <!-- 窗口的布局,这里是垂直的,也可以是水平的   -->   
    <!-- 
    	android:id                ~~~~~~~~~~~~~ 为控件指定相应的ID,以便访问控件
    	android:text              ~~~~~~~~~~~~~ 指定控件当中显示的文字,这里尽量使用string.xml文件中定义的string
    	android:grivity           ~~~~~~~~~~~~~ 指定控件中显示的内容在控件中所处的位置
    	android:textSize          ~~~~~~~~~~~~~ 指定控件当中字体的大小
    	android:background        ~~~~~~~~~~~~~ 指定控件中所指定的背景色,用RGB方法
    	android:layout_width      ~~~~~~~~~~~~~ 控件宽度
    	android:layout_height     ~~~~~~~~~~~~~ 控件高度
    	android:padding*          ~~~~~~~~~~~~~ 控件的内边距
    	android:sigleLine         ~~~~~~~~~~~~~ 如果为真的话,则控件中的内容在同一行中显示,显示不完就用 ...表示
    	-->    
    <TextView 
        android:id="@+id/firstText"
        android:text="first Line"
        android:gravity="center_vertical"
        android:textSize="18pt"
        android:background="#aa0000"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="10dip"
        android:paddingRight="30dip"
        android:paddingTop="20dip"
        android:paddingBottom="10dip"
        android:layout_weight="1"
        android:singleLine="true"/>
    <TextView 
        android:id="@+id/secondText"
        android:text="second Line"
        android:gravity="center_vertical"
        android:textSize="18pt"
        android:background="#00aa00"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="10dip"
        android:paddingRight="30dip"
        android:paddingTop="20dip"
        android:paddingBottom="10dip"
        android:layout_weight="2"
        android:singleLine="true"/>
    <Button
        android:id="@+id/myButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        />
</LinearLayout>

再来看一下表格布局:TableLayout

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="0" >
    <!-- 表示通过拉伸第一列来填满屏幕 -->
    
    <!-- 第一行 -->
    <TableRow>
        <!-- 第一行中设置了三列 -->
    <TextView
        android:text="@string/row1_column1"
        android:background="#aa0000"
  		android:padding="3dip" />
    <TextView
        android:text="@string/row1_column2"
        android:background="#00aa00"
  		android:padding="3dip" />
    <TextView
        android:text="@string/row1_column3"
        android:background="#0000aa"
  		android:padding="3dip" />
    </TableRow>
    
        <!-- 第二行 -->
    <TableRow>
        <!-- 第二行中设置了两列 -->
    <TextView
        android:text="@string/row2_column1"
        android:background="#00aa00"
  		android:padding="3dip" />
    <TextView
        android:text="@string/row2_column2"
        android:background="#0000aa"
  		android:padding="3dip" />
    </TableRow>
</TableLayout>
posted @ 2011-11-01 20:58  哈哈开心  阅读(412)  评论(0编辑  收藏  举报