android - 了解 Android XML @ 前缀

标签 android xml

我试图了解 android XML 文件中的 @ 符号是如何解析的。

例如:

<item type="layout" name="activity_item_list">@layout/activity_item_twopane</item>

@layout 引用系统中的布局。

<FrameLayout android:id="@+id/item_detail_container" android:layout_width="0dp"
    android:layout_height="match_parent" android:layout_weight="3" />

@+id 似乎通过某种魔法将 ID 添加到系统中,我可以在代码中引用:

R.id.activity_item_detail

我的搜索引导我找到了一些随机文章,这些文章似乎无法帮助我理解这些字符是如何解析的。这些只是被视为某种形式的宏\我在哪里可以了解更多关于他的信息?

谢谢 沃里克

最佳答案

http://developer.android.com/guide/topics/ui/declaring-layout.html您可以阅读:

The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource.

The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).

There are a number of other ID resources that are offered by the Android framework. When referencing an Android resource ID, you do not need the plus-symbol, but must add the android package namespace, like so: android:id="@android:id/empty"

有帮助吗?

关于android - 了解 Android XML @ 前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32027596/

相关文章:

java - 使用 ViewPropertyAnimator 淡入图像

android - Android 中的 ServiceManager 类在哪里?

java - Google maps api 没有将标记放置在合适的位置

android - 我怎样才能给小部件的宽度一个百分比而不是一个明确的值?

android - 无法在android上打开xml文件

android - 如何在 AsyncTask 中通过 Json 加载 Spinners

java - 是否可以将事件溯源与 StAX XML 事件序列一起使用

将节点添加到根节点时出现 java.lang.NullPointerException

android - 解析 XML 时出错 : Mismatched tag - Android strange error

java - 在 SAX 解析期间确定根元素