Android 應用軟體開發(六)視窗布局

來源:互聯網
上載者:User

視窗的布局是在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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.