2

I have a floating action button but I need to position it above the bottom tabs. I've tried increasing the bottom margin or changing the layout_anchor, but nothing seems to work. How can I move the floating action bar slightly above the bottom tabs so it doesn't cover it?

This my floating action bar xml:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_gravity="bottom|right|end"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:layout_width="wrap_content"
    android:src="@drawable/ic_add_white_24dp"
    app:layout_anchorGravity="bottom|right|end"
    app:layout_behavior=".FABScrollBehavior" />

screenshot

<?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:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_width="match_parent" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:background="@color/color_primary"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            app:tabTextColor="@android:color/secondary_text_dark"
            app:tabSelectedTextColor="@android:color/primary_text_dark" />

    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_gravity="bottom|right|end"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:layout_width="wrap_content"
        android:src="@drawable/ic_add_white_24dp"
        app:layout_anchorGravity="bottom|right|end"
        app:layout_behavior=".FABScrollBehavior" />

</android.support.design.widget.CoordinatorLayout>
Poly Bug
  • 1,514
  • 1
  • 14
  • 27

1 Answers1

-1

Take All this in relative layout container and use above property in FloatingActionButton then take margin bottom and adjust according you.