2012-02-01 100 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>

相关问题