DrawerLayout中CoordinatorLayout下面的空格

时间:2015-07-07 10:29:53

标签: android android-support-library material-design android-support-design

我正在尝试在CollapsingToolbarLayout内实现DrawerLayout的布局。整个acitivty_main.xml看起来像这样:

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

布局和应用结构基于this tutorial by codepath,我更改了FrameLayout的{​​{1}}(即使效果同时出现)。

现在我打算用于实际内容的视图有一些奇怪的填充(我使用背景颜色来澄清实际渲染的位置):

device capture

我在哪里陷入困境?

2 个答案:

答案 0 :(得分:4)

  

我在哪里陷入困境?

这是设计库的错。布局“短”比屏幕高度导致间隙,折叠/展开<CollapsingToolbarLayout>中的不当行为(即您需要拖拽之外的折叠区域再展开等等等等等。这只是相当的目前还有错误或写下这个答案(希望有一天可以修复,但我不知道何时会发生这种情况)。

答案 1 :(得分:-1)

尝试删除:exitUntilCollapsed

进入CollapsingToolbarlayout,您现在拥有此代码

app:layout_scrollFlags="scroll"