簡單的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"
    android:padding="10dp"
    tools:context=".MainActivity" >
    <!-- android:padding此處定義整個佈局和Activity四周距離,和網頁的padding類同 
    -->
    
    <!-- layout_marginTop 組件距離佈局頂部距離 dp是單位  layout_toLeftOf組件左邊緣
    	對齊靠近指定id的組件。
    -->
     <TextView
         android:id="@+id/user"
         android:layout_marginTop="15dp"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textSize="20dp"
         android:layout_toLeftOf="@+id/passtext"
         android:text="用戶:" />

     <!-- layout_toRightOf組件右邊緣靠近指定id的組件左邊緣 
     	layout_alignBottom 組件底部和指定id的組件底部對齊
     -->
     <EditText
         android:id="@+id/usertext"
         android:layout_toRightOf="@id/user"
         android:layout_alignBottom="@id/user"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="username"
         />
     
     <!--
     	layout_alignBottom 組件底部和指定id的組件底部對齊
     -->
    <TextView
        android:id="@+id/pass"
        android:layout_alignBottom="@id/passtext"
        android:textSize="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密碼:"
        />

     <!-- layout_toRightOf組件右邊緣靠近指定id的組件左邊緣 
     	layout_below 組件處於指定id的組件下部
     -->
     <EditText
         android:id="@+id/passtext"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_below="@id/usertext"
         android:layout_toRightOf="@id/pass"
         android:text="password" />

     <!-- layout_alignParentRight 組件和父佈局右邊靠近對齊
     	layout_below 位於指定id組件下部
     -->
      <Button
         android:id="@+id/cancel"
         android:text="cancel"
         android:layout_alignParentRight="true"
         android:layout_below="@id/passtext"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         ></Button>
      
      <!-- layout_toLeftOf 組件左邊緣和指定id組件右邊緣靠近對齊
     	layout_below 位於指定id組件下部
     -->
     <Button
         android:id="@+id/ok"
         android:text="ok"
         android:layout_toLeftOf="@id/cancel"
         android:layout_below="@id/passtext"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         ></Button>
</RelativeLayout>

佈局效果圖:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章