支持库 23.2.0 中的 CoordinatorLayout IllegalStateException
CoordinatorLayout IllegalStateException in Support Library 23.2.0
最近我使用 Android 支持库版本 23.2.0 更新了我的应用程序,我发现这个库中有一个错误导致应用程序在膨胀片段时崩溃。
这是从 GoogleAnalytics 中看到的错误。到目前为止,我在 Android 6.0、2.3.6 和 4.4.4 中找到了它:
IllegalStateException (@CoordinatorLayout$LayoutParams:resolveAnchorView:2522) {main}
这似乎是支持库中的错误(而且它似乎也影响其他组件)。我已经解决了返回版本 23.1.1 的问题,并且我的应用程序运行良好。我还没有找到崩溃的原因,但这里是导致崩溃的片段。也许你能看到别的东西。
非常感谢!
<?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>
layout_anchor
必须是 CoordinatorLayout
的 child,但您使用的是 coordinator_lines
(即您的 CoordinatorLayout
本身)。
如果您没有特定的 child 需要将您的视图锚定到,只需使用 layout_gravity
而不是 layout_anchorGravity
并完全删除 layout_anchor
。
最近我使用 Android 支持库版本 23.2.0 更新了我的应用程序,我发现这个库中有一个错误导致应用程序在膨胀片段时崩溃。
这是从 GoogleAnalytics 中看到的错误。到目前为止,我在 Android 6.0、2.3.6 和 4.4.4 中找到了它: IllegalStateException (@CoordinatorLayout$LayoutParams:resolveAnchorView:2522) {main}
这似乎是支持库中的错误(而且它似乎也影响其他组件)。我已经解决了返回版本 23.1.1 的问题,并且我的应用程序运行良好。我还没有找到崩溃的原因,但这里是导致崩溃的片段。也许你能看到别的东西。
非常感谢!
<?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>
layout_anchor
必须是 CoordinatorLayout
的 child,但您使用的是 coordinator_lines
(即您的 CoordinatorLayout
本身)。
如果您没有特定的 child 需要将您的视图锚定到,只需使用 layout_gravity
而不是 layout_anchorGravity
并完全删除 layout_anchor
。