【发布时间】:2010-10-09 02:01:11
【问题描述】:
我有两个 Android 项目,一个包含自定义布局的“库项目”和一个包含使用该布局的应用程序的“应用程序项目”。
一切似乎都可以正常构建和执行,除了可视布局编辑器抛出 ClassNotFoundException(我认为这是插件中的一个错误),但是当我尝试开始使用我为xml 中的自定义布局,我无法再构建。那是;这行得通:
<?xml version="1.0" encoding="utf-8"?>
<se.fnord.android.layout.PredicateLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdfasdf"
/>
</se.fnord.android.layout.PredicateLayout>
而这不是:
<?xml version="1.0" encoding="utf-8"?>
<se.fnord.android.layout.PredicateLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fnord="http://schemas.android.com/apk/res/se.fnord.android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
fnord:layout_horizontalSpacing="1px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdfasdf"
/>
</se.fnord.android.layout.PredicateLayout>
构建失败并带有来自 aapt 的消息:
错误在包“se.fnord.android”中找不到属性“layout_horizontalSpacing”的资源标识符
R 文件中确实存在资源标识符,并且 attrs.xml 包含库项目,如果我将布局代码和资源直接放在应用程序项目中,一切正常。 layout_horizontalSpacing 属性(和 layout_verticalSpacing)是 PredicateLayout.LayoutParam 类中用于指定到下一个小部件的距离的自定义属性。
到目前为止,我已经通过指定项目引用和构建路径项目依赖项尝试了标准的 eclipse 方式。我还被告知尝试应用程序清单中的标记,但没有帮助。
那么,我需要做什么才能使 xml 文件中的引用起作用?
我不知道它是否相关,但“库”清单如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="se.fnord.android"
android:versionCode="1" android:versionName="1.0.0">
</manifest>
“应用程序”清单如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="se.fnord.appname"
android:versionCode="1" android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AppName"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
(顺便说一句,'PredicateLayout' 是 this 的清理版本)。
【问题讨论】:
标签: android eclipse dependencies