简体   繁体   中英

How to put Floating Action Button in the bottom of the screen with Collapsing ToolBar to be always visible

I have fragment with floating action button inside activity with collapsing toolbar. When toolbar is collapsed everything is ok, but when it's expended, FAB is not visible (it's below the screen). Here is xml of my fragment with FAB:

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

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/layout">


<ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_anchor="@+id/layout"
    app:layout_anchorGravity="bottom|right|end"
    />


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

replace

app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"

with

android:layout_gravity="bottom|end"

This should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM