顯示具有 Android版面設計 標籤的文章。 顯示所有文章
顯示具有 Android版面設計 標籤的文章。 顯示所有文章

2011年5月24日 星期二

ScrollView物件

ScrollView物件當資料訊息過大,導致物件僅顯示部分資料時
可以使用ScrollView物件,將所有的訊息顯示出來

<ScrollView
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    >
    <TextView 
        android:id="@+id/msg"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text=""    />
</ScrollView>

RelativeLayout版面配置

RelativeLayout版面配置相對佈局版面配置,可指定一物件位於另一物件的相對位置(上下左右)
Default設定,物件位於左上角

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    >
    <TextView
        android:id="@+id/key_msg"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="15pt"
        android:text="Please press all keys."  />
    <TextView
        android:id="@+id/key_menu"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/key_msg"
        android:text="Menu"  />
    <TextView
        android:id="@+id/key_back"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/key_menu"
        android:text="Back"  />
    <TextView
        android:id="@+id/key_vol_add"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/key_back"
        android:text="Volume +"  />
    <TextView
        android:id="@+id/key_vol_dec"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/key_vol_add"
        android:text="Volume -"  />
    <Button
        android:id="@+id/pass"
        android:layout_width="150px"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"        android:text="PASS"  />
    <Button
        android:id="@+id/fail"
        android:layout_width="150px"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"        android:layout_alignParentRight="true"        android:text="FAIL"  />
</RelativeLayout>

2011年4月13日 星期三

LinearLayout版面配置

LinearLayout版面配置
線性佈局版面配置,每一行只放一個物件,依方向可分為垂直及水平方向

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"   
        android:layout_height="fill_parent"
        <!-- 切割視窗的屬性 -->
        android:layout_weight="1">
        <SurfaceView
            android:layout_width="wrap_content"   
            android:layout_height="wrap_content"   
            android:layout_gravity="center"/>
    </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"   
        android:layout_height="fill_parent"
        android:layout_weight="1">   
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Run Time"/>
       <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Stop!!"/>
    </LinearLayout>
</LinearLayout>

假設一個Layout裡包含了2個LinearLayout,分別是LinearLayout_A和LinearLayout_B
當android:layout_weight的屬性分別設定為(3,2)時
LinearLayout_A會占全部畫面的2/(3+2)
LinearLayout_B會占全部畫面的3/(3+2)