在我的project中,我已经创建了一个全局的头layoutglobal_header.xml
,而且我通过用<include layout="@layout/global_header.xml">
把它用在了我所有的布局XML文件中。
之前我用过这个方法,现在我在这个project中用这个方法。我的问题的是我有一个layout用的下边的content:
<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="@global/header">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
</ScrollView>
</RelativeLayout>
global_header.xml的contents:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android: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>
我在 android:layout_below="@global/header"
得到了一个错误:
error: Error: No resource found that matches the given name (at 'layout_below' with value '@global/header').
我之前在project的其他layout中用过,没有问题,但是不知道什么原因,这个layout文件不能像其他的layout一样从头文件处加载ID。
有这个问题的话project就不能build,尽管我知道一旦在设备中运行的话这不是个问题,还有人遇到过这个问题么?有什么解决办法么?
<include layout="@layout/global_header" android:id="@+global/header"/>
1、再定义一个id:
<include layout="@layout/global_header"
android:id="@+id/global_other"/>
android:layout_below="@global/global_other"
2、使用LinearLayout 垂直布局,设置android:orientation="vertical"