如何在CollapsingToolbarLayout折叠结束时隐藏ImageView?

7

我在CollapsingToolbarLayout中使用ImageView,并需要对它进行控制,在CollapsingToolbarLayout折叠结束时隐藏它,并对其进行一些操作。请问有什么好的想法可以帮助我吗? 以下是可选项:

app:layout_scrollFlags="scroll|exitUntilCollapsed"
但是没有任何像“exitEndCollapsed”这样的选项。

刚刚点赞了这个问题。你有这个答案吗? - VVB
2个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
20

我花了将近两天的时间才把这个问题解决了。 我阅读了很多指南和其他文章。 现在我终于解决了! 这是我所做的步骤:
首先,您需要将 ImageView 移动到工具栏之前(仍位于 CollapsingToolbarLayout 内)。 接下来,您必须将 app:contentScrim =“?attr / colorPrimary” 添加到 CollapsingToolbarLayout 中(它会产生滚动结束时的漂亮效果)。
最后,您需要将 android:background =“@android:color / transparent”添加到您的 Toolbar 中。
就是这样...这样对我有用。 希望能帮到你。

这是我的activity_main.xml的一部分:

<android.support.design.widget.CoordinatorLayout 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:id="@+id/sceneRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="168dp">

    <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">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@mipmap/ic_launcher"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:background="@android:color/transparent"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_collapseMode="pin"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:paddingBottom="16dp"
            android:paddingStart="16dp"
            android:text="AppBar Title"
            android:textSize="25dp" />

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

<android.support.v4.widget.NestedScrollView
    android:id="@+id/scrollView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

不错的解决方案 :) 它节省了我的时间 - Prashant Jajal
1
谢谢,救了我的一天! - ARiF
它对我有用,不错的解决方案。 - Rizwan

0
在你的图像视图中只需添加 ","
 app:layout_collapseMode="parallax"
 app:layout_collapseParallaxMultiplier="0"         

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,