android - 自定义 ListView - 如何将 attrs.xml 设置为命名空间

标签 android

我关注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:dropShadowBottomottasee: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/

相关文章:

android - 如何显示一个 View 3 秒,然后隐藏它?

java - for 循环内的 AlertDialog

android - 如何修复 android studio 中的 "design editor is not available until a successful build"

java - java 中 Class<T[]> 的实例,以便在 json 解析器中使用

android - CircleCI 将 Artifact 发布到云服务器?

android - 为什么通过 SupportFragmentManager 添加 fragment 的顺序很重要?

java - Android 强制回收大位图?

android - 为什么我的 fragment 的 ontouch() 和 onClick() 方法在启动另一个框架时仍然响应

android - 什么是适配器中的转换 View ?它是如何运作的?

android - 如何为 Android 谷歌地图 v2 调整自定义标记图标的大小?