视图不能锚定到父协调器布局



我刚刚从 23.1.1 更新到 appcompat 库,现在应用程序停止在 java.lang.IllegalStateException:视图无法锚定到父 CoordinatorLayout。

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

崩溃来自父级resolveAnchorView CoordinatorLayout方法(协调器布局未处于编辑模式)。布局用作基本活动中的根元素,并包含不同的布局(工具栏、进度条和最后的相对布局,具有膨胀的活动布局。

<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>
您无法将

布局锚点属性设置为坐标器布局本身 app:layout_anchor="@id/base_activity__main_layout",这是错误的,您需要将协调器的一些直接子级设置为此布局锚点

最新更新