简体   繁体   中英

Floating Action Button not overlapping Bottom Sheet

I have the problem that my Floating Action Button is not overlapping over the Bottom Sheet in a Coordinator Layout. How can I solve this problem? The underlying layout is a Map Fragment.

The layout looks like this

The XML looks a following:

<?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">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButtonAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="-32dp"
        android:layout_gravity="end|top"
        android:src="@drawable/ic_add_white_48dp"
        app:backgroundTint="@color/colorPrimary"
        app:borderWidth="0dp"
        app:elevation="4dp"
        app:fabSize="normal"/>

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

        <!-- include bottom sheet -->
        <include layout="@layout/bottom_sheet_peek" />

        <!-- include main content -->
    <include layout="@layout/bottom_sheet_content" />

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

Try set positive marginTop at LinearLayout and remove negative one from FAB:

<?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">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButtonAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|top"
        android:src="@drawable/ic_add_white_48dp"
        app:backgroundTint="@color/colorPrimary"
        app:borderWidth="0dp"
        app:elevation="4dp"
        app:fabSize="normal"/>

    <LinearLayout

        android:layout_marginTop="32dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/linear_layout_bottom_sheet">

        <!-- include bottom sheet -->
        <include layout="@layout/bottom_sheet_peek" />

        <!-- include main content -->
        <include layout="@layout/bottom_sheet_content" />

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

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