我有一個標準的頁眉佈局,我想將其包含在所有我的活動佈局中。這是非常簡單的:包含的xml layout_width/height找不到
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:background="@drawable/header_bg" >
<Button
android:id="@+id/new_client_button"
android:layout_width="@dimen/client_btn_width"
android:layout_height="@dimen/client_btn_height"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/search_btn_bg"
android:text="@string/find_client" />
<ImageView
android:id="@+id/header_logo"
android:layout_width="@dimen/header_logo_width"
android:layout_height="@dimen/header_logo_height"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="@string/OK"
android:src="@drawable/negev_logo" />
</RelativeLayout>
我已經將它包括在幾個活動中,並且一切正常。然而,在下面的聲明,我從Eclipse的投訴,說「‘client_header’不設置所需layout_width屬性:」
這是聲明,我看不到任何東西在這裏,不存在其他的,成功的佈局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
tools:context=".ClientActivity" >
<include
android:id="@+id/client_header"
layout="@layout/header_layout" />
... etc
當我嘗試膨脹佈局時,我也得到一個運行時異常與相同的錯誤。有什麼想法嗎?
添加android:layout_width =「match_parent」 android:layout_height =「wrap_content」包含標記 –
可能是您在包含的佈局上方添加了一些其他佈局。因爲您正在以相對佈局添加它 – deniz