【问题标题】:Unexpected CoordinatorLayout behavior意外的 CoordinatorLayout 行为
【发布时间】:2015-11-08 14:12:29
【问题描述】:

这是我用来创建可折叠工具栏动画的 xml:

主要布局:

   <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <android.support.design.widget.AppBarLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:fitsSystemWindows="true">
                <include layout="@layout/toolbar"/>
        </android.support.design.widget.AppBarLayout>
            <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </android.support.design.widget.CoordinatorLayout>

工具栏布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    style="@style/AppTheme.toolbarStyle"
    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="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"/>

替换container FrameLayout的布局:

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

我得到的结果:

现在明显的问题是,Recyclerview 被绘制在工具栏下方,并且列表只有在工具栏完全隐藏后才开始滚动。预期的动画是在隐藏工具栏的同时滚动回收视图。从我读到的可能是因为 CoordinatorLayout 是 FrameLayout 的子类。我该如何解决?

【问题讨论】:

  • 工具栏的包含不适用于 AppBarLayout:code.google.com/p/android/issues/detail?id=175526
  • 如果您查看 gif,您会发现它确实有效。
  • 为什么有FrameLayout 容器而不仅仅是@+id/recycler_list?无论如何,我推荐这个指南,也许你会找到解决问题的方法:inthecheesefactory.com/blog/…
  • 我正在使用片段转换来替换内容,其中一个可用的内容是 recyclerview。

标签: android xml android-recyclerview androiddesignsupport android-coordinatorlayout


【解决方案1】:

将此添加到您的FrameLayout (@+id/container):

app:layout_behavior="@string/appbar_scrolling_view_behavior"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-04
    • 2016-07-16
    • 2016-05-10
    • 2020-07-23
    • 2021-08-23
    • 2021-11-16
    • 2017-10-20
    • 2016-06-29
    相关资源
    最近更新 更多