2014-01-30 20 views
0

我有一個標準的頁眉佈局,我想將其包含在所有我的活動佈局中。這是非常簡單的:包含的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 

當我嘗試膨脹佈局時,我也得到一個運行時異常與相同的錯誤。有什麼想法嗎?

+0

添加android:layout_width =「match_parent」 android:layout_height =「wrap_content」包含標記 –

+0

可能是您在包含的佈局上方添加了一些其他佈局。因爲您正在以相對佈局添加它 – deniz

回答

0

事實證明,這是文件中進一步縮小格式的副作用。該佈局未被標記,但不知何故它影響了上面的XML代碼。故事的寓意:不要認爲bug是在Eclipse的lint認爲它的地方。就像任何其他錯誤一樣,直到你解決了問題纔會簡化。

1
<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:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_world" /> 

<include 
    android:id="@+id/client_header" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignRight="@+id/textView1" 
    android:layout_below="@+id/textView1" 
    android:layout_marginRight="25dp" 
    android:layout_marginTop="94dp" 
    layout="@layout/layout_name" /> 
</RelativeLayout> 

這種佈局適合我。

0

取下父padding layout.Because它的一個基本視圖如果您需要填充或者使用Margin對孩子的看法或者使用其它包裝layout內舉行的TextView和ImageView的和該設置填充。