Reputation: 28579
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.
Upvotes: 2
Views: 2286
Reputation: 3261
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>
Upvotes: 5
Reputation: 10969
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.
Upvotes: 1