2013-03-26 22 views
0

嗨,如果你看看java的最上面的容器可能是「窗口」或「JFrame」,我們將在其中放置所有其餘的gui組件。在Android中,對於每項活動,我們都會在xml中定義一個用於與此活動一起使用的佈局。所以當這個活動加載時,它會加載關聯的佈局。那麼這個佈局在哪裏繪製。我的意思是首先它會創建一個默認窗口,並開始繪製它的佈局或如何發生?Android中最重要的容器是什麼?

+0

這是查看檢查參考http://developer.android.com/reference/android/view/ViewGroup.html – Pragnani 2013-03-26 11:01:49

+0

謝謝。我發現窗戶是視圖中最頂層的容器。 – Murray9654 2013-03-26 20:54:29

回答

0

一些信息讓我們假設下面是你的XML佈局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 

     android:scaleType="center" 
     android:src="@drawable/golden_gate" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dip" 
     android:layout_gravity="center_horizontal|bottom" 

     android:padding="12dip" 

     android:background="#AA000000" 
     android:textColor="#ffffffff" 

     android:text="Golden Gate" /> 

</FrameLayout> 

這個XML以下視圖層次將被創建:

enter image description here

DecorView直到目前android版本實際上是一個FrameLayout

此信息是從羅馬人的博客,檢查出this link欲瞭解更多信息..

+0

在圖中最上面的容器是PhoneWindow $ DecorView。那麼PhoneWindow是什麼。是Phones桌面或我們的應用程序創建一個並將佈局放入其中。爲什麼我問這是在java佈局是合乎邏輯的。他們沒有圖形表示。這裏看起來相反。在這裏,我認爲佈局bu本身就是一個容器,像java中的「窗口」。我的理解是正確的嗎? – Murray9654 2013-03-26 12:02:52

0

我認爲,活動的內容(即你setContentView設置)嵌入在FrameLayout,你可以像這樣訪問:

View root = findViewById(android.R.id.content); 
+0

非常感謝。 – Murray9654 2013-03-26 20:56:43

0

層次,觀衆在獨立棄用,請monitor

+0

謝謝你。這非常有幫助。 – Murray9654 2013-03-26 13:52:53

0

最上面的容器是內部類DecorView,它是FrameLayout的擴展。您可能會發現它here