gpt4 book ai didi

android - 如何解决 LinearLayout.LayoutParams 与 CoordinatorLayout.LayoutParams 的 ClassCastException

转载 作者:行者123 更新时间:2023-11-30 01:00:26 25 4
gpt4 key购买 nike

我正在尝试创建一个 FloatingActionButton,如 this , 但是当我运行应用程序时出现以下错误

 java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.design.widget.CoordinatorLayout$LayoutParams
at android.support.design.widget.FloatingActionButton$Behavior.isBottomSheet(FloatingActionButton.java:597)
at android.support.design.widget.FloatingActionButton$Behavior.onDependentViewChanged(FloatingActionButton.java:589)
at android.support.design.widget.FloatingActionButton$Behavior.onDependentViewChanged(FloatingActionButton.java:528)

这是我的 layout.xml 文件

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/discoverRView"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/description_layout"
android:padding="8dp"
android:background="@color/colorPrimaryDark"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_margin="5dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="@color/color_white_light" />
<TextView
android:layout_width="match_parent"
android:layout_margin="4dp"
android:layout_height="match_parent"
android:lines="5"
android:scrollHorizontally="true"
android:ellipsize="end"
android:textColor="@color/color_event_text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp"
android:id="@+id/textView2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/red_color"
android:id="@+id/fr_youare_at">

<TextView
android:paddingLeft="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/you_are_at"
android:layout_gravity="center_vertical|left"
android:textColor="@android:color/white"
android:text="Interested"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>


</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@android:drawable/ic_menu_search"
app:layout_anchor="@id/description_layout"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>

我做错了什么?

最佳答案

我已经解决了,调用 app:layout_anchor 标签的布局必须是 CoordinatorLayout 的直接子节点

关于android - 如何解决 LinearLayout.LayoutParams 与 CoordinatorLayout.LayoutParams 的 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39517521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com