layout01.jpg

所謂的LinearLayout就是將在<LinearLayout></LinearLayout>之間的元件按照先後順序來呈現。LinearLayout又分兩個方向,垂直(vertical)以及水平(horizontal),而決定verticalhorizontal的屬性為Orientation

android:orientation=”vertical”

LinearLayout範例:

範例中,使用了三個<TextView>元件,這三個<TextView>元件皆以垂直向下(vertical)的方式排列呈現。此範例使用setContentView來顯示main.xml,故只需要修改專案中的res/layout/main.xml即可。

main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<TextView 

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="元件01"

    android:textSize="27sp"

    />

<TextView 

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="元件02"

     android:textSize="27sp"

    />

<TextView 

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="元件03"

     android:textSize="27sp"

    />

</LinearLayout>

p.s Suggestion using “sp” because it will be change size according to the size of screen.

執行畫面:

layout03.jpg  

 

Layout常用屬性表

layout07.jpg  


 

arrow
arrow
    文章標籤
    android LinearLayout Layout
    全站熱搜

    S 發表在 痞客邦 留言(0) 人氣()