2012-02-01 102 views
0
android的xml文件

,我經常看到兩種不同的格式:<TextView /> OR <TextView></TextView>

<TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/DrawableResources" /> 

OR

<TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/DrawableResources" ></TextView> 

他們是一樣的嗎?在<TextView></TextView>之間的android中沒有內容的所有XML標記是否可以用兩種格式編寫?

+1

耶兩者都是相同的簡寫。 – Akram 2012-02-01 09:22:48

+0

沒有區別,只有一個是速記。 – JoxTraex 2012-02-01 09:41:07

回答

0

是的,這是所有XML文檔中可用的語法快捷方式,適用於不帶主體的標籤。我更喜歡前者,但你可以寫一個。

0

是,是速記<tag></tag>

0

是的,這是一樣的。在你看到它在HTML和ASP標籤,如

<asp:Label ID="lblName" runat="server" Text="Example" /> 

存在時

0

無子元素是這可以在兩個方面寫的一樣,兩者都是相同的。

Generaly以下方式在如果視圖是父視圖情況下使用,需要在其中包含一些其他視圖,這樣的視圖被稱爲視圖基團如線性佈局,RealtiveLayout,滾動視圖等

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/DrawableResources" > 

<TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/DrawableResources" /> 

</LinearLayout> 
1

是的,他們都是一樣的!

<TextView/><TextView></TextView>

相關問題