Aharon Manne
Aharon Manne

Reputation: 712

Included xml layout_width/height not found

I have a standard header layout that I want to include in all my activity layouts. It is very simple:

<?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>

I have included it in several activities, and everything is OK. However, in the following declaration, I get complaints from Eclipse saying '"client_header" does not set the required layout_width attribute:'

This is the declaration, I can't see anything here that doesn't exist in other, successful layouts:

<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

I also get a runtime exception with the same error when I try to inflate the layout. Any thoughts?

Upvotes: 0

Views: 862

Answers (3)

user2944178
user2944178

Reputation: 59

<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>

This layout worked for me.

Upvotes: 1

Aharon Manne
Aharon Manne

Reputation: 712

It turns out that this was a side effect of a malformed layout further down in the file. That layout was not flagged, but somehow it affected the XML code above it. The moral of the story: don't assume that the bug is at the place that Eclipse's lint thinks it is. Just like any other bug, simplify until you have isolated the problem.

Upvotes: 0

Viswanath Lekshmanan
Viswanath Lekshmanan

Reputation: 10083

Remove the padding from the parent layout.Because its a base view If you need padding either use Margin for child views or use other wrapper layout within that to hold textView and ImageView and set padding for that.

Upvotes: 0

Related Questions