總網頁瀏覽量

2013年2月17日 星期日

relativelayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <RelativeLayout
 android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
(相對位置擺在父容器裏頭的頂端)
        >
    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Guess"
        />
   
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/btn"
//告訴edittext位於Button的左手邊
         android:layout_alignTop="@id/guess"
     android:layout_alignBottom="@id/guess"
(向guess分別頂端對齊、底部對齊,讓版面看起來更工整)
      />
</RelativeLayout>
<LinearLayout
 android:id="@+id/bottom"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  >
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
(讓button的大小平均分配在LinearLayout。如果父親容器是RelativeLayout,則不能用此屬性)
    android:text="newgame"
android:background="#AFD1E3"
    />
    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
android:layout_weight="1"
    android:text="setting"
android:background="#AFD1E3"
    />

    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
android:layout_weight="1"   
android:text="help"
android:background="#AFD1E3"
(設定按鈕顏色:可以去color picker抓顏色的編碼)
    />
  </LinearLayout> 
<TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#D1957D"
        android:layout_above="@id/bottom"
(指定TextView相對位置)
        android:layout_below="@id/top"
  (指定TextView相對位置)
若沒寫上面這兩行TextView就會填充整個螢幕


/>
 

</RelativeLayout>



沒有留言:

張貼留言