View can not be anchored to the parent CoordinatorLayout
Asked Answered
P

1

9

I just updated to appcompat library from 23.1.1 to 23.2 and now application stopped working on java.lang.IllegalStateException: View can not be anchored to the the parent CoordinatorLayout.

java.lang.IllegalStateException: View can not be anchored to the the parent CoordinatorLayout

Crash comes from resolveAnchorView method of CoordinatorLayout when parent (CoordinatorLayout is not in edit mode). Layout is used as root element in base activity and contains different layouts (toolbar, progressbar and finally relativelayout with inflated layout of activity.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/base_activity__main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/shared__color_primary">

    <ProgressBar
        android:id="@+id/base_activity__progress_bar_top"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:visibility="gone" />

    <ViewSwitcher
        android:id="@+id/base_activity__switcher"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/base_activity__progress_bar_top">

        <LinearLayout
            android:id="@+id/base_activity__progress_bar_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/_loading"
                android:textStyle="italic" />

            <ProgressBar
                android:id="@+id/base_activity__progress_bar"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:indeterminate="true" />
        </LinearLayout>

        <RelativeLayout
            android:id="@+id/base_activity__main_content_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </ViewSwitcher>

    <RelativeLayout
        android:id="@+id/base_activity__add_button__container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent" />

</android.support.design.widget.CoordinatorLayout>
Polis answered 2/3, 2016 at 12:50 Comment(7)
where is this layout base_activity__main_layoutAscanius
it is coordinator laytout contains this xml, but problem was caused with this line app:layout_anchor="@id/base_activity__main_layout", but I still do not understand whyPolis
so the co ordinator layout is in a different file? and you are adding this layout that you have attached in your question by inflating it in a fragment?Ascanius
no it is single xml file, example in question inside coordinatorlayoutPolis
is this base_activity__add_button__container a direct child of the cordinator layout?Ascanius
full layout is updated in question nowPolis
seems that to "layout_anchor" must be assigned a control that is child of the CoordinatorLayout and not the coordinator layout itself. Try to set layout_anchor to ViewSwitcher for exampleExtensometer
A
17

You cannot set the layout anchor attribute to the co ordinator layout itself app:layout_anchor="@id/base_activity__main_layout", this is wrong, you need to set some direct child of the co ordinator as this layouts anchor

Ascanius answered 3/3, 2016 at 4:0 Comment(3)
thanks , that works for me, in new support library version , we cannot direct anchor coordinator layoutFiery
exactly as Luci said 13 hours ago, thnxPolis
@Polis its been long enough looks like luci doesn't want to post her answer, you may as well mark this rightAscanius

© 2022 - 2024 — McMap. All rights reserved.