Rendering Problems using FloatingActionButton betw

2019-02-20 06:46发布

问题:

As I mentioned in the question, my FloatingActionButton between two layouts, check classic example here, stopped working after updating gradle dependencies to 24.2.0.

I have checked similar questions and answers. After digging, I found an answer explaining the reason, see here. The solutions is extremely useful for cases where you want to place the FAB at the bottom of the layout. However, this is not working between two layouts.

Sorry for creating another question/issue, and not continuing the discussion in the solution I found, but apparently, I don't have enough reputation to create a comment.

Thanks in advance for your time.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".Screens.DetailActivity">

<LinearLayout
    android:id="@+id/project_detailed_holder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:transitionName="tMainHolder">

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </FrameLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/article_list_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/article_collection"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:requiresFadingEdge="vertical" />

    </LinearLayout>
</LinearLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fabEdit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_mode_edit_black_24dp"
    android:tint="@android:color/white"
    app:layout_anchor="@id/header"
    app:backgroundTint="@color/colorPrimary"
    app:elevation="4dp"
    app:layout_anchorGravity="bottom|right|end"
    android:alpha="0.0"/>


</android.support.design.widget.CoordinatorLayout>

回答1:

layout_anchor only works with direct children of CoordinatorLayout. You'll need to change your layout_anchor to use a different view, such as your project_detailed_holder.