2013-01-10 30 views
2

我遵循this指南为我的应用制作自定义ListView。本教程使用名为ottasee的名称空间,应将其定义为元素内的xml名称空间。因此,这里是我的一些代码:自定义ListView - 如何将attrs.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> 

我应该如何才能抓住从attrs.xml文件的属性定义为ListView 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?

回答

2

您应该添加以下内容包括对您的命名空间的必要属性如下: xmlns:ottasee ="http://schemas.android.com/apk/res-auto"

与@ budius的回答略有不同,因为它会自动为您解析软件包名称。

1

通常的XML编辑器为你做,我甚至从来没有担心过,但它是这样的:

xmlns:ottasee="http://schemas.android.com/apk/res/com.your.package.name" 
+0

感谢您的回答。你能看看我的编辑吗? –