Fabian Falkowski
Fabian Falkowski

Reputation: 1

Include doesn´t realy include anything

I just cleaned my .xml files and outsourced the header and footer elements of every file. after that my projekt runs into an error but only in 2 of 8 files.

the old code:

<ImageView
android:layout_width =                      "wrap_content"
android:id =                                "@+id/ImageView01"
android:layout_height =                     "60dp"
android:src =                               "@drawable/logo"
android:scaleType =                         "fitXY">

and the new code:

<include layout="@layout/header" /

The error says "No resource found that matches the given name (at 'layout_below' with value '@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">

i can´t imagine why it works in nearly every file but not in those two. it´s just copy and paste and all the rest is the same.

Upvotes: 0

Views: 622

Answers (3)

JohnnyLambada
JohnnyLambada

Reputation: 12826

I tried johnnycube's answer, but it didn't fix it for me. The problem ends up being that aapt needs a -S parameter for each resource directory when an <include> is done. For some reason ADT doesn't make this happen properly. Also, when multiple -S's are used, aapt needs --auto-add-overlay. Needless to say the ADT doesn't support modifying the aapt command, so I ended up writing a wrapper around aapt that would detect the situation and add the -S <dir> --auto-add-overlay. The script is below. You'll need to modify the KEY to detect the project you're modifying, and DIR to be a relative link to the /res/ directory of your library project.

#!/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)

Upvotes: 0

Johnnycube
Johnnycube

Reputation: 1060

This one really took me a lot of thinking and finally ended up in disbelieve....

I had the exact same problem using a RelativeLayout with include

In part of my .xml files i could reference to id inside the include. In others not.

layout_head.xml contains the Layout to be included. I used the following statement:

<?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>

I saw that this works in every xml file that was alphabetically below layout_head.xml. So i renamed layout_head.xml to aalayout_head.xml and of course switched the include statement to the new name - et voila - works in every file...

Seems to be a problem with the Eclipse Plugin rather than the Android System itself.

Wierd enoug but thankfully its working now flawlessly.

Btw: Any idea why my layout did not work when I used android:layout_below="@id/cell1" ?

Upvotes: 5

jakebasile
jakebasile

Reputation: 8132

You are probably using RelativeLayout to place things below your titlebar. You need to put an id on the <include /> tag as well, because it doesn't look for IDs inside an include. Weird problem, but a simple fix:

<include 
    layout="@layout/header" 
    android:id="@+id/ImageView01" />

Upvotes: 0

Related Questions