2017-02-27 6 views
2

Ich habe ein App-Layout mit einem benutzerdefinierten toolbar und einem persistenten BottomSheet - beide innerhalb einer CoordinatorLayout.Persistente BottomSheet unter ActionBar

Auf einen Knopf klicken möchte ich die BottomSheet zeigen. Jetzt wird das Blatt im Vollbildmodus angezeigt und überlagert die toolbar. Durch Einstellen des App-Designs auf Theme.AppCompat.Light.DarkActionBar bleibt die BottomSheet unter der ActionBar, aber die Leiste kann nicht angepasst werden.

Gibt es eine Möglichkeit, die Höhe des persistenten BottomSheet auf Vollbild - ActionBar Höhe zu begrenzen?

Dies ist mein Code in activity_main.xml

<android.support.design.widget.CoordinatorLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:attrs="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.test.MainActivity"> 

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

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     app:elevation="20dp" 
     android:elevation="20dp" 
     android:layout_height="?attr/actionBarSize"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      app:elevation="20dp" 
      android:elevation="20dp" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary"/> 
    </android.support.design.widget.AppBarLayout> 
    </LinearLayout> 
    <include layout="@layout/bottom_sheet_additem"/> 
</CoordinatorLayout> 

Hier ist der Code von sheet_bottom.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/bottomSheetLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/colorAccent" 
    app:behavior_hideable="true" 
    app:behavior_peekHeight="0dp" 
    android:fitsSystemWindows="true" 
    app:layout_behavior="@string/bottom_sheet_behavior"> 

    <TextView 
     android:id="@+id/bottomsheet_text" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:text="Lorem Ipsum Dolor..." 
     android:textColor="#FFFFFF" /> 
</RelativeLayout> 

Screenshot Das Bild auf der linken Seite zeigt die BottomSheet, die unterhalb der Toolbar hält - das ist funktioniert nicht mit meinem aktuellen Code. Momentan sieht es wie das Bild rechts aus.

+0

können Sie einen Screenshot hochladen? –

+0

Screenshots zur Frage hinzugefügt - EDIT – nor0x

+0

Wie wäre es, wenn Sie versuchen, ein Layout setzen Sie die Höhe von unten auf der Symbolleiste und machen Sie die Unterseite es Kind und dann stellen Sie es auf seine Elternhöhe (das neue Layout) –

Antwort

1

Ich hatte das gleiche Problem.

Versuchen Sie, setzen Sie Ihre in einem anderen CoordinatorLayout in Ihrem activity_main.xml mit einem MarginTop wie folgt umfassen:

<android.support.design.widget.CoordinatorLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:attrs="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.test.MainActivity"> 

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

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      app:elevation="20dp" 
      android:elevation="20dp" 
      android:layout_height="?attr/actionBarSize"> 

      <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      app:elevation="20dp" 
      android:elevation="20dp" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary"/> 
     </android.support.design.widget.AppBarLayout> 
    </LinearLayout> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="56dp"> 

     <include layout="@layout/bottom_sheet_additem"/> 

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

</CoordinatorLayout> 

Lassen Sie mich wissen, ob es auch für Sie gearbeitet.

0

Wir App verwenden: layout_behavior statt fester Höhe

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <include layout="@layout/bottom_sheet_additem"/> 

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