我关注this为我的应用程序制作自定义 ListView
的指南。本教程使用名为 ottasee 的命名空间,该命名空间应定义为元素内的 xml 命名空间。这是我的一些代码:
<com.my.app.Layout.CustomListView
xmlns:ottasee="what_should_i_put_here?"
android:id="@+id/lastCases"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@null"
android:scrollbars="none"
ottasee:dropShadowBottom="true"
ottasee:dropshadowrightsrc="@drawable/drop_shadow"
/>
我可以看到属性 ottasee:dropShadowBottom
和 ottasee:dropshadowrightsrc
是值文件夹中 attrs.xml
的一部分。像这样:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<declare-styleable name="DropShadowListView">
<attr format="boolean" name="dropShadowLeft"></attr>
<attr format="reference" name="dropShadowLeftSrc"></attr>
<attr format="boolean" name="dropShadowRight"></attr>
<attr format="reference" name="dropShadowRightSrc"></attr>
<attr format="boolean" name="dropShadowTop"></attr>
<attr format="reference" name="dropShadowTopSrc"></attr>
<attr format="boolean" name="dropShadowBottom"></attr>
<attr format="reference" name="dropShadowBottomSrc"></attr>
</declare-styleable>
</resources>
我应该如何为 ListView
定义 xml 命名空间,以便从 attrs.xml
文件中获取属性?
谢谢!
编辑
我的 CustomListView 位于包 com.my.app.Layout
下,我尝试以这种方式声明 ns: xmlns:ottasee="http://schemas.android.com/apk/res/com.my.app.Layout
但我只在 xml 文件中收到错误:
Multiple annotations found at this line:
- error: No resource identifier found for attribute 'dropShadowBottom' in package
'com.my.app.Layout'
- error: No resource identifier found for attribute 'dropshadowrightsrc' in package
'com.my.app.Layout'
如何设置正确的 ns?
最佳答案
您应该添加以下内容以将必要的属性包含到您的命名空间中:
xmlns:ottasee="http://schemas.android.com/apk/res-auto"
与@budius的答案略有不同,因为它会自动为您解析包名称。
关于android - 自定义 ListView - 如何将 attrs.xml 设置为命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14254482/