2013-01-10 28 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

感謝您的回答。你能看看我的編輯嗎? –