偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

詳解Android Widget組件RelativeLayout實(shí)例

移動(dòng)開(kāi)發(fā)
本文為Javaeye的網(wǎng)友倚風(fēng)聽(tīng)雪對(duì)關(guān)于RelativeLayout的一些看法,小編覺(jué)得內(nèi)容很不錯(cuò),介紹給大家,希望大家喜歡,同時(shí)也希望讀者關(guān)注51CTO的Mobile Widget專(zhuān)題。

以前很少用RelativeLayout,但是這次筆者的項(xiàng)目用到了RelativeLayout。用起來(lái)才發(fā)現(xiàn)RelativeLayout太靈活了。很容易給人造成一些錯(cuò)誤。

51CTO推薦專(zhuān)題:Mobile Widget

下面談?wù)劰P者的看法。

引用

  1. From Tutorials:  
  2.  
  3. If you find yourself using several nested LinearLayout groups, you may be able toreplace them with a single RelativeLayout  
  4.  

以上來(lái)自Tutorials,筆者理解的觀(guān)點(diǎn)是,當(dāng)有過(guò)個(gè)ViewGroup嵌套的時(shí)候,再去考慮用RelativeLayout,筆者覺(jué)得既然官方這么寫(xiě),很程度是因?yàn)?,RelativeLayout太靈活了,它的靈活性給我們對(duì)UI的控制多少回造成一定影響。

曾經(jīng)有人跟筆者說(shuō)過(guò),RelativeLayout跟FrameLayout有一些相似,給人的感覺(jué)是分層的。有層的這個(gè)概念。
筆者覺(jué)得不是這樣的,是沒(méi)有層的概念的。從官方的解釋上可以看出這東西就是可以設(shè)置相對(duì)布局的一個(gè)布局而已。沒(méi)有層的概念。

先上段代碼,更直觀(guān)的看看。

Java代碼

  1. <?xml version="1.0" encoding="utf-8"?>    
  2. <RelativeLayout    
  3.     xmlns:android="http://schemas.android.com/apk/res/android"    
  4.     android:layout_width="fill_parent"    
  5.     android:layout_height="fill_parent"    
  6.     android:background="#CCFFFF">    
  7.     <LinearLayout    
  8.         android:id="@+id/linearLayout"    
  9.         android:layout_width="fill_parent"    
  10.         android:layout_height="200dp"    
  11.         android:background="#32000033"    
  12.         android:orientation="vertical">    
  13.         <Button    
  14.             android:id="@+id/button1"    
  15.             android:layout_width="fill_parent"    
  16.             android:layout_height="wrap_content"    
  17.             android:background="#FF3300"    
  18.             android:text="Button" />    
  19.         <TextView    
  20.             android:id="@+id/textView"    
  21.             android:layout_width="fill_parent"    
  22.             android:layout_height="wrap_content"    
  23.             android:layout_weight="1"    
  24.             android:text="Base"    
  25.             android:textColor="#6633FF"    
  26.             android:gravity="center" />    
  27.         <Button    
  28.             android:id="@+id/button2"    
  29.             android:layout_width="fill_parent"    
  30.             android:layout_height="wrap_content"    
  31.             android:background="#FF3300"    
  32.             android:text="Button" />    
  33.     </LinearLayout>    
  34.     <Button    
  35.         android:id="@+id/button3"    
  36.         android:layout_width="100dp"    
  37.         android:layout_height="50dp"    
  38.         android:layout_centerInParent="true"    
  39.         android:layout_alignBottom="@id/linearLayout"    
  40.         android:text="button" />    
  41. </RelativeLayout>   

只貼xml,activity沒(méi)什么東西,就顯示一下罷了。

運(yùn)行效果圖

運(yùn)行效果圖

很明顯可以看出button3的下邊緣是跟lineLayout的下邊緣在一條水平線(xiàn)上的。

Java代碼
 

  1. android:layout_alignBottom="@id/button1"    

但是當(dāng)像上面一樣設(shè)置的時(shí)候,我們可能會(huì)是想讓button3的下邊緣跟button1的下邊緣在一個(gè)水平線(xiàn),但是這些寫(xiě)的效果卻不是按我們所想的顯示,如此設(shè)置根本不起作用。

運(yùn)行效果圖

這其中的原因,筆者是這樣認(rèn)為的,首先,linearLayout,Button這些組件都是在android.widget這個(gè)包中的。他們是同一級(jí)別的。只是說(shuō)linearLayout是一個(gè)ViewGroup可以再包含其他的View而已。不存在其他的優(yōu)先級(jí)關(guān)系。

所以,筆者的理解是,如果Button3這個(gè)控件要同其他控件產(chǎn)生相互關(guān)系的話(huà),首先他們是要位于同一級(jí)別的。(此處說(shuō)的級(jí)別不是說(shuō)組件級(jí)別,而是在xml文件里面設(shè)置的級(jí)別,如:linearLayout和button3是一級(jí)的話(huà),那button2,textView,button3既是二級(jí))
只有同一級(jí)別的才能設(shè)置關(guān)系,否則的話(huà)設(shè)置相互之間的位置關(guān)系就不會(huì)起作用。

這就是筆者的理解,根本不存在層的概念。 

【編輯推薦】

  1. Windows Phone 7 免費(fèi)線(xiàn)下培訓(xùn)火熱報(bào)名中
  2. 解析Android Widget開(kāi)發(fā)中如何構(gòu)建Activity類(lèi)
  3. Android Widget開(kāi)發(fā)詳解
  4. Android Widget開(kāi)發(fā)系列解讀
  5. Android Widget工具箱
責(zé)任編輯:佚名 來(lái)源: javaeye
相關(guān)推薦

2011-09-08 13:11:07

Android Wid實(shí)例

2011-09-08 15:51:33

Android Wid組件

2011-09-09 20:14:58

Android Wid

2010-07-13 09:02:19

Widget開(kāi)發(fā)

2011-09-13 15:35:40

Widget

2011-09-07 17:54:40

Android Wid開(kāi)發(fā)

2011-09-07 14:01:41

Android Wid實(shí)例

2011-09-07 14:20:42

Android Wid組件

2011-09-07 10:58:07

Android wid

2011-09-07 13:18:40

Android Wid

2011-09-07 13:42:36

Android Wid實(shí)例

2011-09-08 15:40:45

Android Wid組件

2011-09-07 10:34:48

Android Wid

2011-09-08 14:01:01

Android Wid實(shí)例

2011-09-08 15:29:50

Android Wid界面GridView

2011-09-09 13:23:17

Widget

2011-09-08 13:36:26

Android Wid播放器

2011-09-07 13:06:04

Android Wid

2013-12-25 09:34:26

Android SDKAndroid組件

2011-09-08 13:41:53

Widget
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)