2

In my project I have created a global header layout global_header.xml and I use it in all of my layout XML files by using <include layout="@layout/global_header.xml">.

I have used this method before, and I am currently using it in this project. My problem is that I have a layout with the following contents:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFFFF" >

    <include layout="@layout/global_header" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/global_header">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

Contents of global_header.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/global_header"
    android:layout_width="fill_parent"
    android:layout_height="60sp"
    android:layout_alignParentTop="true"
    android:background="#FFDDDDDD" >

    <ImageView
        android:id="@+id/global_header_logo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5sp"
        android:layout_marginTop="5sp"
        android:adjustViewBounds="true"
        android:src="@drawable/header" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1sp"
        android:layout_alignParentBottom="true"
        android:background="#FF000000" />

</RelativeLayout>

And I am getting an error on android:layout_below="@global/header" saying that:

error: Error: No resource found that matches the given name (at 'layout_below' with value '@global/header').

I have used the include in other layouts in the project and it works without a problem, but for whatever reason, this layout file will not load the ID from the header where as all other layouts do.

The project will not build with this error even though I am sure that once running on the device it will find it not a problem, has anyone else had this problem? Is there solution/workaround?

Any and all help is greatly appreciated.

Matt Clark
  • 27,671
  • 19
  • 68
  • 123

2 Answers2

5

Try this, specify id for include layout and use

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" >

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

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/header">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </RelativeLayout>
</ScrollView>

MuraliGanesan
  • 3,233
  • 2
  • 16
  • 22
  • That is what I had to end up doing, but it is weird that it works in all of my other layouts just fine, and it is just this one that is giving me problems in. – Matt Clark Jan 31 '13 at 05:29
  • Its working for me.. i have specified id for `include layout`. And then use `layout_below` its working for me – MuraliGanesan Jan 31 '13 at 05:36
  • Also check this answer: https://stackoverflow.com/q/11668718/1306012 it says that "the thing is you have to use `@+id/` the first time each id is mentioned and then use `@id/` afterwards, even though the first time may not be a definition." – Bruno Bieri Jun 24 '19 at 08:20
1

Hope both xml (main.xml & global_header.xml) is exist in your layout folder within resources.

kindly clean the project and restart your eclipse, it works.

Note@ I checked your xmls I didn't got any error.

RobinHood
  • 10,897
  • 4
  • 48
  • 97
  • I have done both of those things.. I have had this problem before with random files and the only solution was to copy the data into each file which was ugly.. for now I have solved the problem by using `` and took the ID out of the header file. – Matt Clark Jan 31 '13 at 05:17