java - 折叠工具栏布局: How to make a view disappear when collapsed

标签 java android android-layout material-design android-collapsingtoolbarlayout

我用了this创建折叠工具栏的教程,以创建与此类似的布局:enter image description here

我希望当整个工具栏折叠时书籍缩略图消失。但不知何故,这就是正在发生的事情:

enter image description here

这是我的 XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:fitsSystemWindows="true"
    tools:context=".activities.GFSBookContentActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/white"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/book_cover"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            app:layout_collapseMode="parallax"
            android:scaleType="centerCrop" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_centerVertical="true"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" >
            <ImageView
                android:id="@+id/back"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_centerVertical="true"
                android:src="@drawable/ic_arrow_back"
                android:textStyle="bold"
                android:tint="@color/gfs_blue" />
        </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"
    android:clipToPadding="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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


<ImageView
    android:id="@+id/book_cover_thumb"
    android:layout_width="150dp"
    android:layout_height="200dp"
    android:layout_gravity="center_horizontal"
    android:scaleType="fitXY"
    app:layout_anchor="@id/appbar"
    app:layout_anchorGravity="bottom|center"
    app:layout_collapseMode="parallax" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_height="50dp"
    android:layout_width="50dp"
    app:layout_anchor="@id/appbar"
    app:layout_anchorGravity="bottom|right|end"/>

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

我尝试添加 FAB,但它消失了。我希望我的图像缩略图具有这种行为。另外,您知道如何将缩略图像我提供的图像一样缩小吗?

最佳答案

看到的事情是 ImageView“book_cover_thumb”无法自动滚动并消失,因为它没有像 FloatingImageButton“fab”那样的任何滚动行为。要使 ImageView “book_cover_thumb”滚动并消失,您必须创建一个自定义行为类并将其设置为 ImageView “book_cover_thumb”。

您可以引用此链接: http://saulmm.github.io/mastering-coordinator

关于java - 折叠工具栏布局: How to make a view disappear when collapsed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50211573/

相关文章:

android - 几乎填满整个屏幕的 map fragment

java - 在 Java 中通过 XSLT 分解 XML

java - Java REST 的正确心跳/保持 Activity 技术/层是什么? http? TCP?编码: chunked?

android - 如何在android中创建火焰?

java - 如何在 Android 设备上使用 DPI 正确绘制以英寸为单位的精确长度?

java - 在 WebView 中为我的 Android 应用程序使用自定义 (unicode) 字体

android - 如何在android textview中进行文本对齐并同时使用自定义字体样式?

java - Spark 使用不同的 TTL 写入 Cassandra

java - 当我们在 spring mvc 中创建自定义处理程序映射时,默认处理程序映射是否会被覆盖?

java - 异步 TCP 连接