折叠工具栏布局 |滚动和布局问题

CollapsingToolbarLayout | Scrolling and layout issues

相关问题

问题

我一直在使用 Android Support Design Library 并成功实现 CoordinatorLayout 导致 ToolbarTabLayout 在滚动时滚出视图。这非常有效,所以我想我会用新的 CollapsingToolbarLayout.

试试运气

在单独的 activity 中,我一直在 issue-after-issue 实施 CollapsingToolbarLayout。正如他们所说,我关闭但没有雪茄。

我想使用 2 个不同的片段

  1. Header 图片 (目前只有一个 ImageView)
  2. "Scrollable" content(实际上内容不是真正可滚动的,但我强迫它使用长 Lorem Ipsum 文本进行测试)

我自己构建了一个这种布局的示例,但在多次尝试后无法正常工作。最后,我找到了这个 [enter image description here][5] 并对其进行了修改以达到我现在的状态

问题

注意:我不知道这些是1件事(多米诺骨牌效应)造成的,还是个别的。此外,我已经查看了很多相关问题,但 none 似乎有任何这些问题。

  1. Scrollable Content 显示在 Header 图像上方
  2. Scrollable Content 未锚定到 Header Image
  3. 的底部
  4. 在滚动 Scrollable Content 时,它会滚动 Header Image 看似随机的:

    • Just right并跟随手指的速度(完美)
    • Too fast 并通过将我的手指移动 1 行文本的高度
    • 使 Header Image 动画离开屏幕
    • 同样在 Scroll down,上述 2 种效果与第 3 种效果一起发生

      • Instant or Near instant "animation" 全宽显示 Header Image

编辑: 下面这些是在另一个问题中问到的!!

  1. CollapsingToolbarLayout 不允许我展开 Toolbar 以查看 完整 Header Image

    • 它显示了图像的大部分,但不是全部。 Top被切掉了,但底部可见
  2. Toolbar设置为Pin但滚动时隐藏

    • 只是Header Image应该消失

代码

总体布局

<android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.AppBarLayout>

        <android.support.design.widget.CollapsingToolbarLayout>

            <ImageView/> <!-- Will be a fragment later -->

            <android.support.v7.widget.Toolbar/>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView>

        <fragment/>  <!-- Not a scrolling fragment layout -->

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

Layout.xml

<android.support.design.widget.CoordinatorLayout 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"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="16dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|enterAlways">

            <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/download"

                android:scaleType="centerCrop" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/anim_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"

                app:layout_collapseMode="pin" />

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/imageView1">

        <fragment
            android:id="@+id/detail"
            android:name="<package>.<fragment_name>"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

1 2 3

4 5 6

您需要将 app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到您的 NestedScrollView - 这标志着 class 应位于 AppBarLayout 下方(因此,位于 [=13 下方) =]).