Search code examples
androidandroid-coordinatorlayoutfloating-action-button

FloatingActionButton covered by prev layout in CoordinatorLayout


This is my xml code.

<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
    android:layout_height="300dp"  
    android:background="#0000FF"
    android:id="@+id/dialog_frame"
    android:orientation="vertical"
    android:elevation="24dp">


</LinearLayout>


<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_anchor="@id/dialog_frame"
    android:id="@+id/login_close"
    app:layout_anchorGravity="bottom|center_horizontal"
    android:clickable="true"/>

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

I expect FAB floating on linearlayout, but linearlayout is covering FAB.

My xml code to layout screenshot:

enter image description here

I don't know why this is happening. Something is wrong, I think?


Solution

  • Your LinearLayout have a higher elevation than the FloatingActionButton thats why its hiding behind LinearLayout

    Just remove android:elevation="24dp" from your LinearLayout

    CODE

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <LinearLayout
                android:id="@+id/dialog_frame"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:background="#0000FF"
    
                android:orientation="vertical">
    
    
            </LinearLayout>
    
    
            <android.support.design.widget.FloatingActionButton
                android:id="@+id/login_close"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                app:layout_anchor="@id/dialog_frame"
                app:layout_anchorGravity="bottom|center_horizontal" />
    
        </android.support.design.widget.CoordinatorLayout>
    

    OUTPUT

    enter image description here