[英]CollapsingToolbarLayout and imageview inside it do not collapse
I want the toolbar and imageview to collapse, when the user scrolls up. 当用户向上滚动时,我希望工具栏和imageview折叠。 Since I'm not using a recyclerview, a suggested workaround was to wrap the imageview in a NestedScrollView. 由于我没有使用recyclerview,因此建议的解决方法是将imageview包装在NestedScrollView中。
All of the content below the AppBarLayout, is made up of imageviews, textviews, and many kinds of layouts. AppBarLayout下面的所有内容均由图像视图,文本视图和多种布局组成。 By default such content does not scroll, so I wrapped it in a NestedScrollView. 默认情况下,此类内容不会滚动,因此我将其包装在NestedScrollView中。 This makes the content scroll-able. 这使内容可滚动。 the problem is, that scrolling up now only makes the bottom NestedScrollView move, and the toolbar does not collapse. 问题是,现在向上滚动只会使底部的NestedScrollView移动,而工具栏不会折叠。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.solidcolorlabs.android.solid.activities.ExampleActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="200dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll">
<ImageView
android:id="@+id/venue_image"
android:layout_width="match_parent"
android:layout_height="200dp" />
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin"
app:navigationContentDescription="@string/abc_action_bar_up_description"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
将LinearLayout更改为CoordinatorLayout。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.