首頁(yè) 收藏 QQ群
 網(wǎng)站導(dǎo)航

ZNDS智能電視網(wǎng) 推薦當(dāng)貝市場(chǎng)

TV應(yīng)用下載 / 資源分享區(qū)

軟件下載 | 游戲 | 討論 | 電視計(jì)算器

綜合交流 / 評(píng)測(cè) / 活動(dòng)區(qū)

交流區(qū) | 測(cè)硬件 | 網(wǎng)站活動(dòng) | Z幣中心

新手入門(mén) / 進(jìn)階 / 社區(qū)互助

新手 | 你問(wèn)我答 | 免費(fèi)刷機(jī)救磚 | ROM固件

查看: 12598|回復(fù): 0
上一主題 下一主題
[教程]

第六講:用戶(hù)界面 View(二)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
發(fā)表于 2013-8-28 16:19 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
671
本講內(nèi)容:常用Layout介紹: AbsoluteLayout和RelativeLayout
點(diǎn)此下載:
  
再在WVGA800的模擬器下看看顯示效果:
  
Tip: 在絕對(duì)定位中,如果子元素不設(shè)置layout_x和layout_y,那么它們的默認(rèn)值是0,也就是說(shuō)它會(huì)像在FrameLayout一樣這個(gè)元素會(huì)出現(xiàn)在左上角。
4、相對(duì)布局 RelativeLayout
相對(duì)布局 RelativeLayout 允許子元素指定它們相對(duì)于其父元素或兄弟元素的位置,這是實(shí)際布局中最常用的布局方式之一。它靈活性大很多,當(dāng)然屬性也多,操作難度也大,屬性之間產(chǎn)生沖突的的可能性也大,使用相對(duì)布局時(shí)要多做些測(cè)試。
下面我們用相對(duì)布局再做一次上面的例子,首先放置一個(gè)圖片,其它兩個(gè)文本分別相對(duì)上一個(gè)元素定位:
   
   
  1. <?xml version=”1.0″ encoding=”utf-8″?><RelativeLayout android:id=”@+id/RelativeLayout01″   
    android:layout_width=”fill_parent”   
    android:layout_height=”fill_parent”   
    android:background=”#fff”   
    xmlns:android=”http://schemas.android.com/apk/res/android”><ImageView android:id=”@+id/ImageView01″   
    android:src=”@drawable/android”   
    android:layout_width=”fill_parent”   
    android:layout_height=”wrap_content”   
    android:layout_marginTop=”40dip”   
    >   
    </ImageView>   
    <TextView   
    android:layout_height=”wrap_content”   
    android:layout_width=”wrap_content”   
    android:id=”@+id/TextView01″   
    android:text=”Android2.2 學(xué)習(xí)指南”   
    android:textColor=”#0f0″   
    android:textSize=”28dip”   
    android:layout_below=”@id/ImageView01″   
    android:layout_centerHorizontal=”true”   
    android:layout_marginTop=”10dip”>   
    </TextView>   
    <TextView   
    android:layout_height=”wrap_content”   
    android:layout_width=”wrap_content”   
    android:id=”@+id/TextView02″   
    android:text=”圖文并茂,理論清晰,操作性強(qiáng)”   
    android:textColor=”#333″   
    android:textSize=”18dip”   
    android:layout_below=”@id/TextView01″   
    android:layout_centerHorizontal=”true”   
    android:layout_marginTop=”5dip“>   
    </TextView>   
    </RelativeLayout>
復(fù)制代碼
  
   
讓我們看一下在WQVGA的模擬器下的顯示效果:
  
再看一下在更大屏幕(WVGA800)模擬器上的顯示效果:
  
從上圖可以看到界面效果基本保持了一致,而不是像絕對(duì)定位一樣龜縮在左上角;同學(xué)們看到自動(dòng)縮放的功能是采用了dip做單位帶來(lái)的好處。關(guān)于dip,不懂的同學(xué)可以看我在開(kāi)發(fā)小知識(shí)里寫(xiě)的專(zhuān)門(mén)的文章。
下面介紹一下RelativeLayout用到的一些重要的屬性:
第一類(lèi):屬性值為true或false   
android:layout_centerHrizontal                                           水平居中   
android:layout_centerVertical                                            垂直居中   
android:layout_centerInparent                                           相對(duì)于父元素完全居中   
android:layout_alignParentBOTTom                                     貼緊父元素的下邊緣   
android:layout_alignParentLeft                                          貼緊父元素的左邊緣   
android:layout_alignParentRight                                        貼緊父元素的右邊緣   
android:layout_alignParentTop                                          貼緊父元素的上邊緣   
android:layout_alignWithParentIfMissing                            如果對(duì)應(yīng)的兄弟元素找不到的話就以父元素做參照物
第二類(lèi):屬性值必須為id的引用名“@id/id-name”   
android:layout_below                          在某元素的下方   
android:layout_above                          在某元素的的上方   
android:layout_toLeftOf                       在某元素的左邊   
android:layout_toRightOf                     在某元素的右邊
android:layout_alignTop                      本元素的上邊緣和某元素的的上邊緣對(duì)齊   
android:layout_alignLeft                      本元素的左邊緣和某元素的的左邊緣對(duì)齊   
android:layout_alignBottom                 本元素的下邊緣和某元素的的下邊緣對(duì)齊   
android:layout_alignRight                    本元素的右邊緣和某元素的的右邊緣對(duì)齊
第三類(lèi):屬性值為具體的像素值,如30dip,40px   
android:layout_marginBottom              離某元素底邊緣的距離   
android:layout_marginLeft                   離某元素左邊緣的距離   
android:layout_marginRight                 離某元素右邊緣的距離   
android:layout_marginTop                   離某元素上邊緣的距離
我們?cè)侔焉厦娴睦又匦伦鲆槐椋@一次多放一些屬性在里面,大家試驗(yàn)一下:
   
   
  1. <?xml version=”1.0″ encoding=”utf-8″?><RelativeLayout android:id=”@+id/RelativeLayout01″   
    android:layout_width=”fill_parent”   
    android:layout_height=”fill_parent”   
    android:background=”#cfff” 色彩的設(shè)置是argb,第一個(gè)c是透明度   
    xmlns:android=”http://schemas.android.com/apk/res/android”><ImageView android:id=”@+id/ImageView01″   
    android:src=”@drawable/android”   
    android:layout_width=”wrap_content”   
    android:layout_height=”wrap_content”   
    android:layout_marginTop=”40dip”   
    android:layout_centerHorizontal=”true”>   
    </ImageView><TextView   
    android:layout_height=”wrap_content”   
    android:layout_width=”wrap_content”   
    android:id=”@+id/TextView01″   
    android:text=”Android2.2 學(xué)習(xí)指南”   
    android:textColor=”#0f0″   
    android:textSize=”28dip”   
    android:layout_below=”@id/ImageView01″   
    android:layout_centerHorizontal=”true”   
    android:layout_marginTop=”10dip”>   
    </TextView><TextView   
    android:layout_height=”wrap_content”   
    android:layout_width=”wrap_content”   
    android:id=”@+id/TextView02″   
    android:text=”圖文并茂,理論清晰,操作性強(qiáng)”   
    android:textColor=”#333″   
    android:textSize=”18dip”   
    android:layout_below=”@id/TextView01″   
    android:layout_centerHorizontal=”true”   
    android:layout_marginTop=”5dip”>   
    </TextView><TextView   
    android:layout_height=”wrap_content”   
    android:layout_width=”wrap_content”   
    android:id=”@+id/TextView03″   
    android:text=”alignTop”   
    android:textColor=”#333″   
    android:textSize=”18dip”   
    android:layout_alignTop=”@id/ImageView01″  和ImageView01上邊緣對(duì)齊   
    android:layout_centerHorizontal=”true”>   
    </TextView><TextView   
    android:layout_height=”wrap_content”   
    android:layout_width=”wrap_content”   
    android:id=”@+id/TextView04″   
    android:text=”alignLeft”   
    android:textColor=”#333″   
    android:textSize=”18dip”   
    android:layout_alignLeft=”@id/ImageView01″   
    android:layout_centerHorizontal=”true”>   
    </TextView><TextView   
    android:layout_height=”wrap_content”   
    android:layout_width=”wrap_content”   
    android:id=”@+id/TextView05″   
    android:text=”alignRight”   
    android:textColor=”#333″   
    android:textSize=”18dip”   
    android:layout_alignRight=”@id/ImageView01″   
    android:layout_centerHorizontal=”true”>   
    </TextView><TextView   
    android:layout_height=”wrap_content”   
    android:layout_width=”wrap_content”   
    android:id=”@+id/TextView06″   
    android:text=”alignBottom”   
    android:textColor=”#333″   
    android:textSize=”18dip”   
    android:layout_alignBottom=”@id/ImageView01″   
    android:layout_centerHorizontal=”true”>   
    </TextView>   
    </RelativeLayout>
復(fù)制代碼
  
   
  
好吧今天就講到這里。
   

上一篇:第三十講:URLConnection和HttpClient使用入門(mén)
下一篇:《Android學(xué)習(xí)指南》目錄

本版積分規(guī)則

Archiver|新帖|標(biāo)簽|軟件|Sitemap|ZNDS智能電視網(wǎng) ( 蘇ICP備2023012627號(hào) )

網(wǎng)絡(luò)信息服務(wù)信用承諾書(shū) | 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證:蘇B2-20221768 丨 蘇公網(wǎng)安備 32011402011373號(hào)

GMT+8, 2024-10-21 03:39 , Processed in 0.058482 second(s), 13 queries , Redis On.

Powered by Discuz!

監(jiān)督舉報(bào):report#znds.com (請(qǐng)將#替換為@)

© 2007-2024 ZNDS.Com

快速回復(fù) 返回頂部 返回列表