7

Ich versuche, ein Layout mit einem CollapsingToolbarLayout in einem DrawerLayout zu implementieren. Die ganze acitivty_main.xml sieht wie folgt aus:Whitespace unter CoordinatorLayout in DrawerLayout

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/activity_main__drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- The CoordinatorLayout is used to coordinate (rly) scroll events between different views --> 
    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <!-- The AppBar (everything above the scrolling content) --> 
     <android.support.design.widget.AppBarLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:id="@+id/activity_main__app_bar" 
      android:fitsSystemWindows="true" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <android.support.design.widget.CollapsingToolbarLayout 
       android:id="@+id/activity_main__collapsing_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/appbar_size_expanded" 
       android:minHeight="?attr/actionBarSize" 
       app:expandedTitleMarginEnd="16dp" 
       app:expandedTitleMarginStart="72dp" 
       app:expandedTitleMarginBottom="32dp" 
       app:expandedTitleTextAppearance="@style/ExpandedAppBarTitle" 
       app:contentScrim="?attr/colorPrimary" 
       app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

       <android.support.v7.widget.Toolbar 
        android:id="@+id/activity_main__toolbar" 
        android:layout_height="?attr/actionBarSize" 
        android:layout_width="match_parent" 
        android:fitsSystemWindows="true" 
        android:background="?attr/colorPrimary" 
        app:layout_collapseMode="pin" 
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

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

     <!-- The scrolling content view --> 
     <android.support.v4.widget.NestedScrollView 
      android:id="@+id/activity_main__content_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#CCC333" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

     <!-- The add button --> 
     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/activity_main__floating_action_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="16dp" 
      android:src="@drawable/ic_add_white_24dp" 
      android:clickable="true" 
      app:layout_anchor="@+id/activity_main__app_bar" 
      app:layout_anchorGravity="bottom|right|end" 
      app:borderWidth="0dp" 
      app:elevation="@dimen/fab_elevation" /> 

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

    <!-- The navigation drawer --> 
    <android.support.design.widget.NavigationView 
     android:id="@+id/activity_main__navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@android:color/white" 
     app:menu="@menu/menu_drawer" 
     app:headerLayout="@layout/drawer_navigation_header" /> 

</android.support.v4.widget.DrawerLayout> 

Das Layout und die App-Struktur basiert lose auf this tutorial by codepath, wo ich die FrameLayout für eine NestedScrollView geändert haben (auch wenn der Effekt mit beiden erscheint).

Nun ist die Ansicht, die ich für den eigentlichen Inhalt verwenden möchten, hat einige seltsame Polsterung (Ich habe eine Hintergrundfarbe verwendet, um zu klären, wo es tatsächlich gemacht wird):

device capture

Wo ich auf Chaos tat?

Antwort

2

Wo habe ich versagt?

Es ist Design Library Fehler. Layouts "kürzer" als Bildschirmhöhe verursachen Lücken, Fehlverhalten beim Zusammenklappen/Entfalten <CollapsingToolbarLayout> (dh Sie müssen außerhalb des kollabierten Bereichs ziehen, um es wieder zu entfalten etc, etc, etc. Es ist gerade ziemlich buggy im Moment oder diese Antwort schreiben (es wird hoffentlich eines Tages festgelegt werden, aber ich habe keine Ahnung, wenn dies) passieren wird

+0

ist haben Gibt es eine vorgeschlagene Abhilfe? Mein Sublayout ist ein LinearLayout 'mit' layout_height = "match_parent" 'und darin ein' TextView' mit dem gleichen, ich verstehe nicht, wie es kürzer ist als die Bildschirmhöhe. – heyarne

-1

versuchen, das zu entfernen. exitUntilCollapsed

In CollapsingToolbarlayout Sie jetzt diesen Code

app:layout_scrollFlags="scroll" 
Verwandte Themen