0

So habe ich eine Floating Action Button, die an einem unteren Blatt-Layout verankert ist. Ich klicke dann auf eine Schaltfläche, die den Status des Bottom Sheets auf STATE_HIDDEN setzt. Das untere Blatt verbirgt sich korrekt und eine Snackbar erscheint, der Floating Action Button steigt entsprechend an. Das Problem tritt auf, nachdem die Snackbar geschlossen wurde und der Floating Action Button sich zurücksenkt: Wenn ich den Status des unteren Blatts auf STATE_COLLAPSED zurücksetze, benötigt der Floating Action Button eine Sekunde oder 2, um wieder auf das untere Blatt zu verankern (letzter Screenshot) . Wie entferne ich die Verzögerung? Thanks :)Android Bottom Sheet mit Floating Action Button mit Snackbar Ausgabe

Bilder von Ausgabe

enter image description here

-Code für die Schaltfläche:

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 für das 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> 

Antwort

3

Hallo Ich habe genau das gleiche Problem und zwei Vorschläge:

Option A: Lassen Sie die Snackbar von oben unter der Symbolleiste schweben. Sehen Sie diese Antwort hier: https://stackoverflow.com/a/31746370/5320905

Option B: erhöhen die Höhe des snackbar und zeigen Sie es auf der FAB wie dieses

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);