Search code examples
androidlayoutfloating-action-button

How to position Android Floating Action Button on Seam


I have a Map and an area below representing a BottomSheet.

I would like to position a Floating Action Button on the seam between these two, on the right handside.

Can anyone offer any suggestions on how I might achieve this?

XML follows, thanks for reading.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

    <!-- Map -->

      <com.google.android.gms.maps.MapView 
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:longClickable="true"
        app:cameraZoom="15"
        app:mapType="normal"
        android:layout_above="@+id/botsheet_frame"/>

    <!-- FAB -->

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

      <!-- place holder for basic BottomSheet area-->
      <RelativeLayout
        android:id="@id/botsheet_frame"
        android:background="#ffffff"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_alignParentBottom="true"
        android:padding="6dp">

    <!-- TextView to be added here -->

    </RelativeLayout>
  </RelativeLayout>
  </FrameLayout>

Solution

  • Try using RelativeLayout instead of LinearLayout. And for FloatingActionButton add attribute like this,

    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="end|bottom"