我试图了解 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/