Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make FAB not to be clipped inside bottom navigation bar

i'm trying to overlap the bottom navigation bar with a FAB. I want my navigationbar to look like this:

Desired result

But instead it cuts off the button like so:

current result

How do I prevent the FAB from being cut off? Here's my XML:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mobgen.designsprintapp.ui.main.MainActivity">

    <LinearLayout 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:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:background="?android:attr/windowBackground"
            android:backgroundTint="@color/colorPrimary"
            app:itemBackground="@color/colorPrimary"
            app:itemIconTint="@color/nav_item_color_state"
            app:itemTextColor="@android:color/black"
            app:menu="@menu/navigation" >

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/tools"
                android:layout_width="56dp"
                android:layout_height="56dp"
                android:layout_gravity="center"
                android:layout_marginBottom="8dp"
                android:elevation="6dp"
                android:scaleType="center"
                app:srcCompat="@drawable/play" />
            </android.support.design.widget.BottomNavigationView>
    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>
like image 733
Tim Avatar asked Sep 19 '17 08:09

Tim


2 Answers

Your problem is that you have explicitly specified width and heigh parameters of FloatingActionButton, whereas it cannot take any width/height. app:fabSize parameters specifies 3 sizes for the fab: auto, mini, and normal.

Leave layout_width and layout_height as wrap_content, and specify the desired fab size using app:fabSize="normal" (or other parameter from the list).

Additionally, make BottomNavigationView's height wrap_content, because fab has some internal paddings.


In order to draw a child outside of the enclosing layout apply android:clipChildren="false" to the enclosing ViewGroup.

like image 76
azizbekian Avatar answered Sep 17 '22 13:09

azizbekian


The problem is that the button is inside the navigation bar. Move it outside, so it will fully visible and over the navigation bar.

<LinearLayout 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:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:background="?android:attr/windowBackground"
            android:backgroundTint="@color/colorPrimary"
            app:itemBackground="@color/colorPrimary"
            app:itemIconTint="@color/nav_item_color_state"
            app:itemTextColor="@android:color/black"
            app:menu="@menu/navigation" >

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

        <android.support.design.widget.FloatingActionButton
                android:id="@+id/tools"
                android:layout_width="56dp"
                android:layout_height="56dp"
                android:layout_gravity="center"
                android:layout_marginBottom="8dp"
                android:elevation="6dp"
                android:layout_anchor="@id/navigation"
                android:layout_anchorGravity="top|center"
                android:scaleType="center"
                app:srcCompat="@drawable/play" />
    </LinearLayout>
like image 26
Luca Nicoletti Avatar answered Sep 18 '22 13:09

Luca Nicoletti