5

So I have a Floating Action Button which is anchored to a bottom sheet layout. I then click a button which sets the state of the Bottom Sheet to STATE_HIDDEN. The bottom sheet hides correctly and a snackbar pops up, the Floating Action Button rises accordingly. The issue is after the Snackbar closes and the Floating Action Button sinks back down: when I set the state of the bottom sheet back to STATE_COLLAPSED the Floating Action Button takes a second or 2 to readjust and anchor back onto the bottom sheet (last screenshot). How do I remove the delay? Thanks :)

Images of Issue

enter image description here

Code for the button:

    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);

    final Snackbar mySnackbar
            = Snackbar.make(findViewById(R.id.bottom_sheet_page),
            R.string.map_undoremove, Snackbar.LENGTH_LONG);
    mySnackbar.setAction(R.string.undo_string, new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            mWaypoint = mMap.addMarker(new MarkerOptions().position(mWaypoint.getPosition())
                    .title("Test"));
        }
    });

    mySnackbar.show();

Code for the layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
android:id="@+id/bottom_sheet_page"
tools:context=".Map.MapNavDrawer" >

<!-- Your content -->
<include layout="@layout/activity_maps" />

<!-- Bottom Sheet -->

<LinearLayout
    android:clickable="true"
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:background="#FFFFFF"
    android:orientation="vertical"
    android:padding="16dp"
    app:behavior_hideable="true"
    app:layout_behavior="@string/bottom_sheet_behavior">

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

        <TextView
            android:id="@+id/textViewWaypoint"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/map_waypointtitle"
            android:textStyle="bold"
            android:textColor="@android:color/black" />

        <TextView
            android:id="@+id/textViewLocName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textStyle="italic"
            android:textColor="@android:color/black" />

        <TextView
            android:id="@+id/textViewLocDetails"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textColor="@android:color/black" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom|end"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button2"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:layout_weight="1"
            android:drawableTop="@drawable/ic_edit_black_24dp"
            android:onClick="selectPlace"
            android:text="@string/map_editwaypoint" />

        <Button
            android:id="@+id/button3"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:layout_weight="1"
            android:drawableTop="@drawable/ic_delete_black_24dp"
            android:onClick="deleteWaypoint"
            android:text="@string/map_removewaypoint" />

        <Button
            android:id="@+id/button4"
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:layout_weight="1"
            android:text="@string/map_sharewaypoint"
            android:drawableTop="@drawable/ic_menu_share"
            style="?android:attr/buttonBarButtonStyle"/>

    </LinearLayout>

</LinearLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/map_marker_radius"
    android:tint="@android:color/white"
    app:layout_anchor="@id/bottom_sheet"
    app:layout_anchorGravity="top|end"
    tools:ignore="VectorDrawableCompat" />


</android.support.design.widget.CoordinatorLayout>
Nemus
  • 3,879
  • 12
  • 38
  • 57
Kerjifire
  • 51
  • 1
  • 7
  • Possibly resurrecting the dead but, did you ever manage to properly handle this? The elevation does not work for me and also putting the Snackbar at the top is not an option.I tried it just to see the effect and it was basically taking the button with it at the top of the screen! – MadDim Dec 13 '18 at 08:23
  • Haha yeah wow this is a very very long time ago. I actually ended up hiding the button too as the snackbar was up. Once the snackbar was dismissed I rendered the button again. Not exactly what I wanted but ended up fixing the buggyness of the button. – Kerjifire Dec 14 '18 at 12:48
  • I see. I actually came up with the same solution for now. I tried to force the layout settings once more with no luck. I guess if we need a real solution we would need to play with the coordinator layout behaviors. – MadDim Dec 15 '18 at 01:12

1 Answers1

8

Hi I have exactly the same issue and two suggestions:

Option A: let the snackbar floating from the top below toolbar. See this answer here: https://stackoverflow.com/a/31746370/5320905

Option B: increase the elevation of the snackbar and show it on top of FAB like this

final Snackbar mySnackbar
            = Snackbar.make(findViewById(R.id.bottom_sheet_page),
            R.string.map_undoremove, Snackbar.LENGTH_LONG);
View snackbarView = mySnackbar.getView();
snackbarView.setElevation(30);
p72b
  • 106
  • 2
  • 5
  • The elevation is set in pixels, see [docs](https://developer.android.com/reference/android/view/View#setElevation(float)). So you should rather set it by using `getResources().getDimensionPixelSize(R.dimen.snackbarElevation)` or something else to get your dp elevation in pixels. – AlbAtNf Mar 24 '19 at 11:46