Android视图标记何时需要关闭标签? [英] When are closing tags required with Android view markup?

查看:70
本文介绍了Android视图标记何时需要关闭标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于某些Android XML属性,直到插入格式设置组件之后,您才需要以'>'结束开头标记.例如:

For some Android XML attributes, you don't conclude the opening tag with a '>' until after you've inserted your formatting components. For example:

<EditText 
  android:id="@+id/etEmails"> 
</EditText>

为什么在开始和结束标记中没有EditText组件的定义? 另外,我注意到有些甚至不需要结束标记,它们本身就是XML语句.例如:

Why is there no definition for the EditText component within the opening and closing tags? Also, I noticed that some don't even require closing tags and are just in themselves XML statements. For example:

<Button
  android:text="Subtract 1"
  android:id="@+id/buttSub"
  />

当此XML语句实际上提供与EditText字段相同的组件时,为什么不要求结束语句?

Why does this XML statement not require a closing statement when it practically provides the same components as the EditText field?

  • 是否有一种故障安全的方法来知道哪些需要打开并 关闭语句以获取正确的语法?

  • Is there a failsafe way of knowing which ones require opening and closing statements for proper syntax?

是否有一个列表/引用,列出哪些列表与哪些列表相对应?

Is there a list/reference for which ones do and don't?

这些不同组件之间有什么区别?

What's the difference between these different components?

推荐答案

<Button />是所谓的短标签.这很安全.

The <Button /> is a so called short tag. This is safe.

如果标签没有 body ,则可以忽略结束标签,并在标签末尾添加斜线,这意味着此标签没有子代.

If a tag has no body you can obmit the closing tag and add a slash at the end of the tag which means here this tag has no children.

在xhtml中,<br /><img src="" alt="" />标签的这种表示法很常见.

This notation is very common in xhtml for <br /> and <img src="" alt="" /> tags.

好处是您不需要编写结束标记,这使它更易于阅读,并且如果您有一个巨大的xml文件,则传输的数据更少. (在这种情况下,这并不适用于Android,因为android SDK内部会处理二进制文件.)

The benifit is that you don't need to write the closing tag which makes it simpler to read and if you have a huge xml file there are less data to transport. (This does not count for Android is this case, because the android SDK procudes internally a binary file.)

这篇关于Android视图标记何时需要关闭标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆