0

I have added 2 floating action buttons to my activity. The problem is that I also have a drawer menu and when I open it my floating buttons remain visible. This is how my XML file looks like:

<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.support.v4.widget.DrawerLayout

        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/DrawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="7dp">

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            android:id="@+id/tool_bar"
            layout="@layout/tool_bar"
            ></include>


        <LinearLayout
            android:id="@+id/viewA"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.6"
            android:background="#FF8845"
            android:orientation="horizontal"/>

        <LinearLayout
            android:id="@+id/viewB"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.4"
            android:background="#AF3800"
            android:orientation="horizontal">
        <ListView
            android:id="@+id/listView5"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:layout_height="270dp"></ListView>
        </LinearLayout>



    </LinearLayout>



        <android.support.v7.widget.RecyclerView
            android:id="@+id/RecyclerView"
            android:layout_width="320dp"
            android:layout_height="match_parent"
            android:layout_gravity="left"

            android:background="#ffffff"
            android:scrollbars="vertical">

        </android.support.v7.widget.RecyclerView>

    </android.support.v4.widget.DrawerLayout>


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/button_add_new_friend"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/ic_add_friend"
        app:layout_anchor="@id/viewA"
        app:layout_anchorGravity="bottom|right|end"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/button_user_photos"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="100dp"
        android:clickable="true"
        android:src="@drawable/ic_user_photos"
        app:layout_anchor="@id/viewA"
        app:layout_anchorGravity="bottom|right|end"/>


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

And this is how they look like: enter image description hereenter image description here

Any ideas how I can solve this problem?

Diana
  • 1,417
  • 5
  • 25
  • 48

2 Answers2

1

Move floating buttons declaration in XML to the top of CoordinatorLayout container (before the DrawerLayout declaration). Android draws views from top to bottom.

UPD. As suggested by @JohanShogun, elevation might be the key. FABs probably have default elevation value higher than you have in your DrawerLayout. Try to override it with lower value and if it won't help, have a look at this answer.

Community
  • 1
  • 1
Dmide
  • 6,422
  • 3
  • 24
  • 31
  • 2
    Consider that this may not always be true on lollipop as some views (such as cards) have a default elevation. – JohanShogun Jul 26 '15 at 17:59
1

Set visibility of buttons GONE or INVISIBLE in onDrawerOpened(View view) listener.

Vivek Sinha
  • 1,556
  • 1
  • 13
  • 24