2

このガイドに従ってListView、アプリのカスタムを作成します。このチュートリアルでは、ottaseeという名前空間を使用します。これは、要素内のxml-namespaceとして定義する必要があります。だからここに私のコードのいくつかがあります:

 <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属性とがvaluesフォルダー内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の設定を達成できますか?

4

2 に答える 2

2

名前空間に必要な属性を含めるには、以下を追加する必要があります。 xmlns:ottasee ="http://schemas.android.com/apk/res-auto"

パッケージ名を自動解決するため、@budiusの回答とは少し異なります。

于 2013-01-10T10:04:48.547 に答える
1

通常は XML エディターが自動的に行います。心配したことはありませんが、次のようになります。

xmlns:ottasee="http://schemas.android.com/apk/res/com.your.package.name"
于 2013-01-10T09:40:10.060 に答える