gpt4 book ai didi

android - CollapsingToolbarLayout 设置动画阈值?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:21:47 29 4
gpt4 key购买 nike

在我的应用程序中,当我开始滚动布局时,CollapsingToolbarLayout 几乎立即开始将背景更改为我设置的稀松布颜色。

Before scrolling After start scrolling

有没有办法设置 CollapsingToolbar 开始更改背景的值?

这是我的 XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="eu.ericnisoli.ambrosettiap.activities.MeetingActivity"
android:visibility="visible"
android:id="@+id/container">

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

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:titleEnabled="false">

<RelativeLayout
android:id="@+id/relativeLayout_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
app:layout_collapseMode="parallax">

<FrameLayout
android:id="@+id/frameLayout_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/frameLayout_info">

<ImageView
android:id="@+id/imageView_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/login_bg"
android:scaleType="centerCrop"/>

<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/detail_meeting_gradient" />

<LinearLayout
android:id="@+id/linearLayout_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingEnd="80dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:layout_gravity="bottom">

<TextView
android:id="@+id/textView_meeting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/meeting"
android:textColor="@color/text_grey_1"
android:textSize="@dimen/text_size_14"
android:textAllCaps="true"
/>

<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="@dimen/text_size_16"
android:text="New Text"
/>

</LinearLayout>

</FrameLayout>

<FrameLayout
android:id="@+id/frameLayout_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/grey_2">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="32dp"
android:paddingBottom="32dp">

<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pin_small_icon"
android:layout_marginBottom="4dp"/>

<TextView
android:id="@+id/textView_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_black_1"/>

<TextView
android:id="@+id/textView_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_black_1"/>
</LinearLayout>

</RelativeLayout>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="32dp"
android:paddingBottom="32dp">

<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/cal_small_icon"
android:layout_marginBottom="4dp"/>

<TextView
android:id="@+id/textView_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_black_1"/>

<TextView
android:id="@+id/textView_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_black_1"/>
</LinearLayout>

</RelativeLayout>
</LinearLayout>

</FrameLayout>

</RelativeLayout>

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/event_caps"/>

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

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

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_anchor="@+id/app_bar"
app:layout_anchorGravity="bottom"
app:layout_collapseMode="pin">

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:layout_anchor="@+id/app_bar"
app:layout_anchorGravity="bottom"
android:background="@color/grey_2"
app:tabTextColor="@color/text_black_1"
app:tabSelectedTextColor="@color/text_black_1"
style="@style/DetailTab"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@drawable/shadow"
android:layout_gravity="bottom"/>

</FrameLayout>

<android.support.v4.view.ViewPager
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_marginTop="?attr/actionBarSize"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/frameLayout_title"
app:layout_anchorGravity="bottom|end"/>

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

<ProgressBar
android:id="@+id/progress"
android:layout_width="48dp"
android:layout_height="48dp"
android:indeterminate="true"
android:layout_gravity="center"
android:visibility="gone"/>

</FrameLayout>

最佳答案

对于 26.1 或更高版本,您可以使用 scrimVisibleHeightTrigger属性设置何时显示稀松布覆盖层的高度阈值。

<android.support.design.widget.CollapsingToolbarLayout
app:scrimVisibleHeightTrigger="80dp"
...>

Set the amount of visible height in pixels used to define when to trigger a scrim visibility change.

If the visible height of this view is less than the given value, the scrims will be made visible, otherwise they are hidden.

关于android - CollapsingToolbarLayout 设置动画阈值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34233674/

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