Mat*_*ark 2 xml layout android include
在我的项目中,我创建了一个全局标题布局,global_header.xml并使用它在我的所有布局XML文件中使用它<include layout="@layout/global_header.xml">.
我之前使用过这种方法,目前我在这个项目中使用它.我的问题是我有一个包含以下内容的布局:
<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>
Run Code Online (Sandbox Code Playgroud)
内容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>
Run Code Online (Sandbox Code Playgroud)
我说错了android:layout_below="@global/header":
错误:错误:找不到与给定名称匹配的资源(在'layout_below'中,值为'@ global/header').
我在项目中的其他布局中使用了include,它没有问题,但无论出于何种原因,此布局文件都不会像所有其他布局那样从标题中加载ID.
该项目不会构建此错误,即使我确信一旦在设备上运行它会发现它不是问题,还有其他人有这个问题吗?有解决方案/解决方法吗?
非常感谢任何和所有的帮助.
试试这个,为include layout指定id并使用
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2089 次 |
| 最近记录: |