欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

深入Android 五大布局對(duì)象的應(yīng)用

 更新時(shí)間:2013年04月21日 11:17:00   作者:  
本篇文章小編為大家介紹,深入Android 五大布局對(duì)象的應(yīng)用。需要的朋友參考下

FrameLayout(幀布局),LinearLayout (線性布局),AbsoluteLayout(絕對(duì)布局),RelativeLayout(相對(duì)布局),TableLayout(表格布局)
FrameLayout:
FrameLayout是最簡(jiǎn)單的一個(gè)布局對(duì)象。它被定制為你屏幕上的一個(gè)空白備用區(qū)域,之后你可以在其中填充一個(gè)單一對(duì)象 ,比如,一張你要發(fā)布的圖片。所有的子元素將會(huì)固定在屏幕的左上角;你不能為FrameLayout中的一個(gè)子元素指定一個(gè)位置。后一個(gè)子元素將會(huì)直接在前 一個(gè)子元素之上進(jìn)行覆蓋填充,把它們部份或全部擋?。ǔ呛笠粋€(gè)子元素是透明的)。

     

復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"   
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent"     >
 <!-- 我們?cè)谶@里加了一個(gè)Button按鈕 -->
<Button
     android:text="button"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content" />
<TextView
    android:text="textview"
    android:textColor="#0000ff"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</FrameLayout>

右邊圖片常見為視頻點(diǎn)播,兩張圖片疊放在一起,后一張覆蓋前一張,添加鏈接到播放地址;

LinearLayout:
LinearLayout以你為它設(shè)置的垂直或水平的屬性值,來排列所有的子元素。所有的子元素都被堆放在其它元素之后,因此一個(gè)垂直列表的每一行只會(huì)有 一個(gè)元素,而不管他們有多寬,而一個(gè)水平列表將會(huì)只有一個(gè)行高(高度為最高子元素的高度加上邊框高度)。LinearLayout保持子元素之間的間隔以 及互相對(duì)齊(相對(duì)一個(gè)元素的右對(duì)齊、中間對(duì)齊或者左對(duì)齊)。

LinearLayout還支持為單獨(dú)的子元素指定weight 。好處就是允許子元素可以填充屏幕上的剩余空間。這也避免了在一個(gè)大屏幕中,一串小對(duì)象擠成一堆的情況,而是允許他們放大填充空白。子元素指定一個(gè)weight 值,剩余的空間就會(huì)按這些子元素指定的weight 比例分配給這些子元素。默認(rèn)的 weight 值為0。例如,如果有三個(gè)文本框,其中兩個(gè)指定了weight 值為1,那么,這兩個(gè)文本框?qū)⒌缺壤胤糯?,并填滿剩余的空間,而第三個(gè)文本框不會(huì)放大。

復(fù)制代碼 代碼如下:

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

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical" >

    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:orientation="vertical"

        android:layout_weight="1" >

        <TextView

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:text="hello,welcome to Livingstone&apos;s blog"

            android:textSize="15pt" />     </LinearLayout>

    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:orientation="horizontal"

        android:layout_weight="2" >

        <TextView

            android:layout_width="wrap_content"

            android:layout_height="fill_parent"

            android:layout_weight="2"

            android:background="#aa0000"

            android:gravity="center_horizontal"

            android:text="red" />

        <TextView

            android:layout_width="wrap_content"

            android:layout_height="fill_parent"

            android:layout_weight="1"

            android:background="#00aa00"

            android:gravity="center_horizontal"

            android:text="green" />     </LinearLayout>

</LinearLayout>

AbsoluteLayout:

AbsoluteLayout 可以讓子元素指定準(zhǔn)確的x/y坐標(biāo)值,并顯示在屏幕上。(0, 0)為左上角,當(dāng)向下或向右移動(dòng)時(shí),坐標(biāo)值將變大。AbsoluteLayout 沒有頁邊框,允許元素之間互相重疊(盡管不推薦)。我們通常不推薦使用 AbsoluteLayout ,除非你有正當(dāng)理由要使用它,因?yàn)樗菇缑娲a太過剛性,以至于在不同的設(shè)備上可能不能很好地工作。
RelativeLayout:
RelativeLayout 允許子元素指定他們相對(duì)于其它元素或父元素的位置(通過ID 指定)。因此,你可以以右對(duì)齊,或上下,或置于屏幕中央的形式來 排列兩個(gè)元素。元素按順序排列,因此如果第一個(gè)元素在屏幕的中央,那么相對(duì)于這個(gè)元素的其它元素將以屏幕中央的相對(duì)位置來排列。如果使用XML 來指定這個(gè) layout ,在你定義它之前,被關(guān)聯(lián)的元素必須定義。

復(fù)制代碼 代碼如下:

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

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical" >

    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:orientation="vertical"

        android:layout_weight="1" >

        <TextView

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:text="hello,welcome to Livingstone&apos;s blog"

            android:textSize="15pt" />     </LinearLayout>

    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:orientation="horizontal"

        android:layout_weight="2" >

        <TextView

            android:layout_width="wrap_content"

            android:layout_height="fill_parent"

            android:layout_weight="2"

            android:background="#aa0000"

            android:gravity="center_horizontal"

            android:text="red" />

        <TextView

            android:layout_width="wrap_content"

            android:layout_height="fill_parent"

            android:layout_weight="1"

            android:background="#00aa00"

            android:gravity="center_horizontal"

            android:text="green" />     </LinearLayout>

</LinearLayout>


TableLayout:

TableLayout 將子元素的位置分配到行或列中。一個(gè)TableLayout 由許多的TableRow 組成,每個(gè)TableRow都會(huì)定義一個(gè) row (事實(shí)上,你可以定義其它的子對(duì)象,這在下面會(huì)解釋到)。TableLayout 容器不會(huì)顯示row、cloumns cell 的邊框線。每個(gè) row 擁有0個(gè)或多個(gè)的cell ;每個(gè)cell 擁有一個(gè)View 對(duì)象。表格由列和行組成許多的單元格。表格允許單元格為空。單元格不能跨列,這與HTML 中的不一樣。


復(fù)制代碼 代碼如下:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:stretchColumns="1">
    <TableRow>
        <TextView android:layout_column="1" android:text="Open..." />
        <TextView android:text="Ctrl-O" android:gravity="right" />
    </TableRow>
    <TableRow>
        <TextView android:layout_column="1" android:text="Save..." />
        <TextView android:text="Ctrl-S" android:gravity="right" />
    </TableRow>
    <View android:layout_height="2dip" android:background="#FF909090" /> //這里是上圖中的分隔線
    <TableRow>
        <TextView android:text="X" />
        <TextView android:text="Export..." />
        <TextView android:text="Ctrl-E" android:gravity="right " /> //讓TextView顯示在右面
    </TableRow>
    <View android:layout_height="2dip" android:background="#FF909090" />
    <TableRow>
        <TextView android:layout_column="1" android:text="Quit"
            android:padding="3dip" />
    </TableRow>
</TableLayout>

相關(guān)文章

最新評(píng)論