我刚刚清理了我的.xml文件,并外包了每个文件的页眉和页脚元素。在那之后,我的项目运行到一个错误,但只在2个8个文件。
老代码:
<ImageView
android:layout_width =                      "wrap_content"
android:id =                                "@+id/ImageView01"
android:layout_height =                     "60dp"
android:src =                               "@drawable/logo"
android:scaleType =                         "fitXY">
和新的代码:
<include layout="@layout/header" /错误显示“未找到与给定名称匹配的资源(位于'layout_below‘,值为'@id/searchRelativeLayout')
<LinearLayout 
    android:id =                        "@+id/SearchRelativeLayout"
    android:layout_width =              "fill_parent"
    android:layout_height =             "wrap_content"
    android:orientation =               "horizontal"
    android:layout_below =              "@id/ImageView01"
    android:gravity =                   "center"
    android:layout_marginTop =          "5dip"
    android:paddingRight =              "5dip"
    android:paddingLeft =               "5dip">我不能想象为什么它在几乎每一个文件中都有效,而不是在这两个文件中。这只是复制和粘贴,其余的都是一样的。
发布于 2011-04-15 17:38:08
这一次我真的花了很多时间思考,最终以难以置信的方式结束……
我在使用带有include的RelativeLayout时遇到了完全相同的问题
在我的部分.xml文件中,我可以在include中引用id。在其他情况下则不是。
layout_head.xml包含要包含的布局。我使用了以下语句:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" style="@style/ETActivity">
<include android:id="@+id/cell1" layout="@layout/aalayout_head" />
<ListView android:id="@+id/main_list" android:layout_width="fill_parent"
    android:layout_height="wrap_content"     android:layout_below="@id/layout_spacer" />
</RelativeLayout>我看到这适用于按字母顺序排在layout_head.xml之后的每个xml文件。因此,我将layout_head.xml重命名为aalayout_head.xml,当然也将include语句更改为新名称- et voila -在每个文件中都有效...
似乎是Eclipse插件的问题而不是Android系统本身的问题。
很奇怪,但谢天谢地,它现在工作得无懈可击。
顺便说一下:当我使用android:layout_below=“@id/cell1 1”时,你知道为什么我的布局不起作用吗?
发布于 2011-03-05 13:45:14
你可能是在用RelativeLayout把东西放在标题栏下面。您还需要在<include />标记上放置一个id,因为它不会在include中查找id。奇怪的问题,但有一个简单的解决方法:
<include 
    layout="@layout/header" 
    android:id="@+id/ImageView01" />发布于 2012-11-01 08:58:10
我试过johnnycube的答案,但它不能解决我的问题。问题最终是aapt在<include>完成时需要为每个资源目录提供一个-S参数。由于某些原因,ADT不能正确地实现这一点。此外,当使用多个-S时,aapt需要--auto-add-overlay。不用说,ADT不支持修改aapt命令,所以我最终在aapt周围编写了一个包装器,它将检测情况并添加-S <dir> --auto-add-overlay。脚本如下。您需要修改KEY以检测您正在修改的项目,并将DIR修改为库项目的/res/目录的相对链接。
#!/usr/bin/env python
KEY=r'name-of-your-directory'
DIR='/../../path/to/your/include/res/'
import os
import re
import sys
mydir = os.path.dirname(os.path.realpath(__file__))
real_aapt = "%s/%s" % (mydir,"aapt-real")
#args = sys.argv[1:]
args = sys.argv
found=False
nextisdir=False
newargs=[]
for arg in args:
    if re.search(KEY,arg):
        found=True
    if nextisdir:
        nextisdir=False
        newargs.append("--auto-add-overlay")
        newargs.append("-S")
        newargs.append(arg+DIR)
    if found and arg == '-S':
        nextisdir=True
os.execv(real_aapt,args+newargs)https://stackoverflow.com/questions/5200489
复制相似问题