Android包括布局文件(参考id)
我试图在另一个布局文件(xml)中包含现有布局。要定位这些布局,我需要给包含的布局一个id,以便我能够引用它,例如 我使用以下布局:Android包括布局文件(参考id),android,android-layout,Android,Android Layout,我试图在另一个布局文件(xml)中包含现有布局。要定位这些布局,我需要给包含的布局一个id,以便我能够引用它,例如 我使用以下布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/bar" android:layout_width="fill_par
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
...
</RelativeLayout>
...
我在另一个布局中包含此布局,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/container"
android:background="@drawable/bg"
>
<include android:id="@id/bar" layout="@layout/bar"/>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bar"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
...
</LinearLayout>
</ScrollView>
</RelativeLayout>
...
这很好,我的ScrollView被放置在我的工具栏下面,我可以点击工具栏,而不会被ScrollView截获点击事件
当我试图在不同的布局文件中执行相同操作时,它表示找不到资源@id/bar:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layoutContainer2"
>
<include android:id="@id/bar" layout="@layout/bar"/>
<ScrollView
android:id="@+id/scrollview2"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@id/bar"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
...
</LinearLayout>
</ScrollView>
</RelativeLayout>
...
有人知道这是为什么吗?将
android=“@id/bar”
更改为android=“@+id/someId”将android:id=“@id/bar”
更改为android:id=“@+id/someId”