【问题标题】:Whitespace below CoordinatorLayout in DrawerLayoutDrawerLayout 中 CoordinatorLayout 下面的空格
【发布时间】:2015-09-24 19:03:26
【问题描述】:

我正在尝试在DrawerLayout 内实现带有CollapsingToolbarLayout 的布局。整个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 更改为NestedScrollView(即使两者都出现效果)。

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

我在哪里搞砸了?

【问题讨论】:

  • 你有解决办法吗?

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


【解决方案1】:

尝试删除:exitUntilCollapsed

进入 CollapsingToolbarlayout 你现在有这段代码

app:layout_scrollFlags="scroll"

【讨论】:

    【解决方案2】:

    我在哪里搞砸了?

    这是设计库的错。布局“短于”屏幕高度会导致间隙、折叠/展开时的不当行为&lt;CollapsingToolbarLayout&gt;(即,您需要将折叠区域 拖到 之外以再次展开它等等等等。它只是在那一刻或写下这个答案(希望有一天会修复,但我不知道什么时候会发生)。

    【讨论】:

    • 是否有任何建议的解决方法?我的子布局是LinearLayoutlayout_height="match_parent",在里面是TextView,我不明白它比屏幕高度短。
    • @Marcin Orlowski:这有什么更新吗?现在是 2018 年,仍然面临这个问题。
    • 我同意你的回答,但是whatsApp是怎么做到的?
    • 不知道,但您始终可以编写自己的组件版本,这很可能是他们所做的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 2015-08-23
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多