【发布时间】:2015-09-22 06:18:17
【问题描述】:
我正在尝试使用 NestedScrollView 实现 CollapsingToolbarLayout,它在底部的 NestedScrollView 中显示 TextView,并且不允许、滚动或折叠工具栏。我已经让它与 RecyclerView 一起工作,但不是 NestedScrollView。当我删除 app:layout_behavior="@string/appbar_scrolling_view_behavior 时,工具栏会折叠,但 NestedScrollView 不在 AppBarLayout 下方。有什么解决方案或建议来解决这个问题?
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.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Hello"
android:textColor="#000"
android:textSize="16sp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="134dp"
android:background="@color/primary"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/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.design.widget.CoordinatorLayout>
结果
【问题讨论】:
-
在 CoordinatorLayout 和 NestedScrollView 中添加
android:fitsSystemWindows="true"。接下来将 nestedScrollview 移到 AppBarLayout 上方。 -
@ɥʇᴉɾuɐɹ 刚刚用您的要求更新了我的答案。结果还是一样。
-
@ɥʇᴉɾuɐɹ 如果你有一个简单的工作示例,发布它,我会测试它。
-
在 AppbarLayout 中更改
android:layout_height="300dp"。是的,我之前曾参考过一个项目,让我搜索一下。同时试试这个 -
@ɥʇᴉɾuɐɹ 试过了,还是不行。那个参考有运气吗?
标签: android android-design-library androiddesignsupport android-collapsingtoolbarlayout