android 佈局

1.線性佈局android

線性方向顯示它的子視圖 水平或者垂直佈局

android:orientation="vertical" 表示該佈局下的元素垂直排列;
android:orientation="horizontal" 表示該佈局水平佈局spa

<?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="horizontal" >
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text= "button1"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text= "button2"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text= "button3"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text= "button4"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text= "button5"
        android:layout_weight="1"/>


</LinearLayout>

視圖
圖片描述code

2.相對佈局xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text= "here"/>
    <EditText
        android:id="@+id/entry"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
    <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/entry"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="10dip"
        android:text= "肯定"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/ok"
        android:layout_alignTop="@id/ok"
        android:text= "取消"/>
</RelativeLayout>

如圖
圖片描述blog

3.隨意佈局圖片

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#4400ff00"
    android:orientation="vertical" >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="請輸入收件人的電話號碼"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="phone"
        android:id="@+id/et_phone"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="請輸入信息的內容"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:lines="5"
        android:inputType="textMultiLine"
        android:id="@+id/et_body"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:lines="5"
        android:inputType="textMultiLine"
        android:id="@+id/hello"/>
    <Button
        android:id="@+id/hellobutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/default_message"/>


</LinearLayout>