Ravi Anand
Ravi Anand

Reputation: 5534

Include tag is giving exception at run time in Xamarin .axml layout

I am trying to include/reuse a layout (.axml) in other layout (.axml) but everything seems good at compile time. at run time it's generating an exception as follows:

Unhandled Exception:

Android.Views.InflateException: Binary XML file line #1: You must specify a layout in the include tag: <include layout="@layout/layoutID" /> occurred

Layout having include tag as follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="100"
    android:minWidth="25px"
    android:minHeight="25px"
    android:background="@android:color/background_light">
    <include
        android:layout_height="wrap_content"
        android:layout="@layout/header_partial"
        android:id="@+id/layoutHeaderPartial" />
        <!-- other controls -->
 </LinearLayout>

Partial/reusable layout code as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:clickable="true"
    android:weightSum="100"
    android:orientation="horizontal">
  <LinearLayout
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="20"
      android:gravity="center_horizontal">
    <refractored.controls.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/door_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        app:civ_border_width="0dp"
        app:civ_border_color="#FF000000"
        android:src="@drawable/img1" />
  </LinearLayout>
  <LinearLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:orientation="horizontal"
      android:layout_weight="55"
      android:paddingLeft="5dp"
      android:gravity="left|center_vertical">
    <TextView
        android:id="@+id/lblStatusFixed"
        android:textColor="@color/year"
        android:textSize="10sp"
        android:gravity="left"
        android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Status:" />
    <TextView
        android:id="@+id/lblLockedStatus"
        android:gravity="left"
        android:textColor="@color/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10sp"
        android:paddingLeft="10dp"
        android:layout_marginLeft="5dp"
        android:textStyle="bold"
        android:text="working" />
    <refractored.controls.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/door_lockImg"
        android:layout_width="30dp"
        android:layout_height="30dp"
        app:civ_border_width="0dp"
        app:civ_border_color="#FF000000"
        android:paddingLeft="10dp"
        android:layout_marginLeft="10dp"
        android:gravity="left"
        android:src="@drawable/img2" />
  </LinearLayout>
  <LinearLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="25"
      android:gravity="center">
    <TextView
        android:id="@+id/lastuse"
        android:textColor="@color/year"
        android:layout_width="wrap_content"
        android:gravity="right"
        android:textSize="10sp"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:text="Last use: 8hrs" />
  </LinearLayout>
</LinearLayout>

Everything seems fine at compile time and I can see designer view is working well, but at run time I don't know what's wrong.

Upvotes: 1

Views: 197

Answers (1)

Yupi
Yupi

Reputation: 4470

The problem is that you include android prefix android:layout="@layout/header_partial" but it should be without it like: include layout="@layout/header_partial".

Upvotes: 1

Related Questions