Javier Delgado
Javier Delgado

Reputation: 2383

CoordinatorLayout IllegalStateException in Support Library 23.2.0

Recently I have updated my app using the Android Support Library version 23.2.0 and I have seen that there is a bug in this library causing the app to crash when inflating a fragment.

This is the error seen from GoogleAnalytics. I have found it in Android 6.0, 2.3.6 and 4.4.4 so far: IllegalStateException (@CoordinatorLayout$LayoutParams:resolveAnchorView:2522) {main}

This seems to be a bug in the Support Library (and it seems to affect also other components). I have solved it returning to version 23.1.1 and my app works perfectly. I haven't found the reason of the crash but here you are the fragment that is causing it. Maybe you can see see something else.

Thank you very much!

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:id="@+id/linear_lines"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    >

    <android.support.design.widget.CoordinatorLayout


        android:id="@+id/coordinator_lines"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_above="@+id/relative_date_text"

        >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.design.widget.TabLayout
                android:id="@+id/sliding_tabs"
                style="@style/MyCustomTabLayout"
                android:layout_width="match_parent"
                android:layout_height="@dimen/abc_action_button_min_height_material"
                android:background="@color/blue_soriabus"
                android:elevation="10dp"
                />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                >

                <android.support.v4.view.ViewPager
                    android:id="@+id/vpPager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    />

                <View
                    android:id="@+id/shadow_view"
                    android:layout_width="match_parent"
                    android:layout_height="7dp"
                    android:background="@drawable/toolbar_shadow" />

            </RelativeLayout>

        </LinearLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floating_button_open_map"
            app:borderWidth="0dp"
            app:backgroundTint="@color/blue_soriabus"
            app:elevation="10dp"
            android:src="@drawable/ic_map_white_48dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right|end"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="16dp"
            android:layout_alignParentBottom="true"
            app:layout_anchor="@id/coordinator_lines"
            app:layout_anchorGravity="bottom|right|end"
            />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floating_button_open_calendar"
            app:borderWidth="0dp"
            app:backgroundTint="@color/blue_soriabus"
            app:elevation="10dp"
            android:src="@drawable/ic_calendar_white_36dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="90dp"
            app:layout_anchor="@id/floating_button_open_map"
            app:layout_anchorGravity="top"
            android:layout_gravity="top|right|end"
            />

    </android.support.design.widget.CoordinatorLayout>

    <RelativeLayout
        android:id="@+id/relative_date_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="10dp"
        android:background="@color/blue_soriabus_dark"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        >

        <TextView
            android:id="@+id/date_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/pure_white"
            android:layout_centerInParent="true"
            android:text="Fecha"
            />

    </RelativeLayout>

</RelativeLayout>

Upvotes: 1

Views: 386

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199805

The layout_anchor must be a child of CoordinatorLayout, but you are using coordinator_lines (i.e., your CoordinatorLayout itself).

If you do not have a specific child you need to anchor your view to, just use layout_gravity instead of layout_anchorGravity and remove layout_anchor entirely.

Upvotes: 2

Related Questions