Search code examples
androidxmllayoutlayout-inflaterandroid-inflate

Found Weird layout InflateException


I have found a weird exception which is android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>. And this exception occur only in api 21 and below that in my adapter class on rootView where I am inflating the layout.

rootView = inflater.inflate(R.layout.custom_layout, parent, false);

This is my background file:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/holo_red_dark" />
            <corners android:radius="5dp" />
        </shape>
    </item>

    <item 
        android:bottom="2dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp">
        <shape android:shape="rectangle">
            <solid android:color="@color/login_back" />
            <corners android:radius="5dp" />
        </shape>
    </item>
</layer-list>

This is my xml : Here is my xml I have using in my code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:layout_height="match_parent"
    tools:layout_editor_absoluteY="25dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/ll_top"
            android:layout_alignParentTop="true"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:orientation="horizontal"
                android:background="@drawable/my_background"
                >
            </LinearLayout>
         </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ll_top"
        android:layout_marginTop="-20dp"
        android:orientation="vertical">
    </LinearLayout>
</RelativeLayout>

Solution

  • I think you are using something which is not compatible in lower API . I am sure that you are using ripple , so change that with selector in lower api version , because that does not supported in lower api version.