我尝试创建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>
我做错了什么?
答案 0 :(得分:1)
我已经解决了,调用app:layout_anchor
代码的布局必须是CoordinatorLayout
的直接子代