【问题标题】:CoordinatorLayout leaves empty space at the bottom after scrollingCoordinatorLayout 滚动后在底部留下空白空间
【发布时间】:2015-12-20 00:44:16
【问题描述】:

我正在尝试使用 CoordinatorLayout 实现 Google 的最新设计技巧,但在滚动和视差效果方面存在问题。

显示 Activity 后,一切正常,但当我尝试滚动时出现问题。似乎底部视图未正确展开,向上滚动后,下方出现空白区域。底部视图似乎只有在顶部视图和导航栏之间的初始显示时才大。

看起来像这样:

相关代码:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<CoordinatorLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:expandedTitleMarginStart="72dp"
            app:expandedTitleMarginEnd="16dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"/>
        </CollapsingToolbarLayout>
    </AppBarLayout>

    <ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</CoordinatorLayout>
</FrameLayout>

这种奇怪的行为是随机发生的。有时底部视图可以正常滚动并且不会出现空白区域。我究竟做错了什么?谢谢。

【问题讨论】:

  • 你找到解决办法了吗?
  • @goonerDroid,我没有。最后我停止使用谷歌的图书馆。
  • 我觉得这是协调器布局的预期行为。但不确定。
  • @goonerDroid 不,whatsapp 不会在底部留下空白补丁。
  • 将视图寻呼机包装在线性布局中似乎可以在类似的问题中赋予它重力

标签: android material-design android-coordinatorlayout android-collapsingtoolbarlayout coordinator-layout


【解决方案1】:

我有同样的问题,我注意到每个有这个问题的布局都有

android:fitsSystemWindows="true"

在 CoordinatorLayout 上

删除它解决了我的问题。

【讨论】:

  • 好的,现在工作。我使用的是RecyclerView 而不是ViewPager,我刚刚做到了match_parent。现在它正在工作。
  • 成功了。我从 AppBarLayout 和 CollapsingToolbarLayout 中删除了这一行,它现在正在工作
【解决方案2】:

尝试在你的CollapsingToolbarLayout 中添加Toolbar

 <android.support.design.widget.CollapsingToolbarLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"/>
...
</android.support.design.widget.CollapsingToolbarLayout>

也尝试添加

android:minHeight="?attr/actionBarSize"

ToolbarCollapsingToolbarLayoutAppBarLayout

【讨论】:

    【解决方案3】:

    由于导航标志的原因,android:fitsSystemWindows="true" 不能满足我的需求。

    玩了一些之后,我发现添加另一个具有 0dp hieght 的 CollapsingToolbarLayout 就可以了。

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_scrollFlags="scroll|snap" />
    

    【讨论】:

      猜你喜欢
      • 2016-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-23
      • 1970-01-01
      • 2023-02-05
      • 1970-01-01
      • 2018-11-16
      相关资源
      最近更新 更多