gpt4 book ai didi

android - CollapsingToolbarLayout - 如何固定工具栏和另一个 View 但标题图像仍然有视差?

转载 作者:行者123 更新时间:2023-11-29 02:33:58 25 4
gpt4 key购买 nike

让我们先看看我想要实现的目标:

enter image description here

所以黄色区域将用于文本。它不应该移动。它应该始终处于固定的静态位置。工具栏同样也应该是静态的并且始终固定。但是蓝色部分会有图像。它应该在滚动和视差时缩小。所以如果用户向上滚动图像应该向上滚动并最终随着视差消失。我无法让黄色区域不动。

如果你需要知道,蓝色区域下方是一个scrollView。

如你所知,黄色条实际上是一个具有匹配父项和黄色背景的 TextView ,但我想它可以是任何 View 。让我们看看到目前为止我做了什么:

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="@color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="false">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:layout_collapseMode="pin"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/white"
app:title="SHOPPING BAG"
android:elevation="4dp"/>


<RelativeLayout
android:layout_width="match_parent"
app:layout_scrollFlags="exitUntilCollapsed"
android:layout_height="wrap_content">

<TextView
android:id="@+id/tv_tax_rebate_msg"
fontPath="fonts/Medium-Extd.otf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bright_yellow"
android:lineSpacingExtra="6sp"
android:padding="15dp"
android:text="@string/tax_rebate_disclaimer"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="10sp"/>


<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blue"
android:layout_below="@id/tv_msg"
app:layout_collapseMode="parallax"
android:orientation="vertical"/>

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

//... rest if it is a scrollview, not important

所以我再次遇到这个问题,是当我滚动时黄色区域在移动。我如何做到只有蓝色区域在用户滚动时缩小?黄色区域将包含重要信息,用户永远不会看不到。

最佳答案

您可以使用协调器布局行为来实现您想要的。

基本思想不是将协调器布局设置为对所有内容执行默认行为,而是可以通过创建自定义行为来细化每个 View 。通过这种方式,您可以做一些花哨的事情。

关于android - CollapsingToolbarLayout - 如何固定工具栏和另一个 View 但标题图像仍然有视差?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48092804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com