DrawerLayout中CoordinatorLayout下面的空白 [英] Whitespace below CoordinatorLayout in DrawerLayout

查看:180
本文介绍了DrawerLayout中CoordinatorLayout下面的空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用DrawerLayout内的CollapsingToolbarLayout来实现布局.整个acitivty_main.xml看起来像这样:

I am trying to implement a layout with a CollapsingToolbarLayout inside a DrawerLayout. The whole acitivty_main.xml looks like this:

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

布局和应用程序结构大致基于本教程(按代码路径)FrameLayout更改为NestedScrollView(即使效果同时出现).

The layout and app structure is loosely based on this tutorial by codepath, where I have changed the FrameLayout for a NestedScrollView (even though the effect appears with both).

现在,我打算用于实际内容的视图具有一些奇怪的填充(我使用了背景色来阐明它的实际渲染位置):

Now the view I intend to use for the actual content has some weird padding (I have used a background color to clarify where it is actually rendered):

我在哪里弄糟?

推荐答案

我在哪里弄糟?

Where did I mess up?

这是设计库的错.比屏幕高度短"的布局会导致间隙,折叠/展开<CollapsingToolbarLayout>时的异常行为(即,您需要将折叠区域的外部拖动到折叠区域中,以再次展开,等等,依此类推,等等).或写出这个答案的那一刻(希望有一天会解决,但是什么时候会发生,我一无所知).

It's Design Library's fault. Layouts "shorter" than screen height cause gaps, misbehaviour in collapsing/unfolding <CollapsingToolbarLayout> (i.e. you need to drag outside of collapsed area to unfold it again etc, etc, etc. It's just quite buggy at the moment or writing this answer (it will, hopefully be fixed some day, but I got no clue when this is going to happen).

这篇关于DrawerLayout中CoordinatorLayout下面的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆