2015年3月20日 星期五

Android Layout 編排

1.type 1:


<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="${relativePackage}.${activityClass}" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/edittext"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="message 1" />

        <Button
            android:id="@+id/send"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="發送" />
     
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="horizontal"
         >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="web"
                android:text="發送朋友圈"
                android:textSize="20sp" />

            <CheckBox
                android:id="@+id/check1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ok"
               >
            </CheckBox>
      </LinearLayout>
    </LinearLayout>

</RelativeLayout>


2.將物件設置到中心位置:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:orientation="horizontal"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >

    <!-- Title Of Song -->
    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="#040404"
        android:textSize="18sp"
        android:textStyle="bold"
        android:typeface="sans" >
    </TextView>

   <TextView
        android:id="@+id/titlea"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"   
        android:gravity="center"
        android:textColor="#a18787"
        android:textSize="15sp"
        android:textStyle="bold"
        android:typeface="sans" >
    </TextView>
</RelativeLayout>


3.全螢幕分割兩區之Layout:(最外層一定要為LinearLayout)

 <LinearLayout 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:orientation="horizontal"
    tools:context="${relativePackage}.${activityClass}" >

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_weight="0.5"
        android:layout_height="match_parent"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/my_custom_background" >
     
        <Button
          android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CLick"
            >
            </Button>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_weight="0.5"
        android:layout_height="match_parent"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/my_custom_background" >
    </RelativeLayout>

</LinearLayout>


沒有留言:

張貼留言