繁体   English   中英

滚动时如何为列表视图上方的图像设置动画?

[英]How to animate an image above a listview when scrolling?

我的列表视图上方有一个图像,目前什么都不做。但是我希望当用户像这样在列表视图中滚动时,我的图像能够被动画化。

这是一个名为StikkyHeader的旧库的示例,但它现在似乎不起作用。 是否有任何其他图书馆出于同样的原因,甚至没有图书馆我可以做到这一点?

试试这个

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:minHeight="200dp"
        >



        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:minHeight="150dp"
            app:expandedTitleMarginBottom="25dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            >

            <ImageView
                android:layout_width="match_parent"
                android:src="@drawable/magic_bg"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.5"
                android:layout_height="match_parent"/>

            <TextView
                android:layout_width="match_parent"
                android:text="#KeepMakingMagic"
                android:textSize="25dp"
                android:gravity="center"
                android:textColor="@color/white"
                android:textStyle="bold"
                app:layout_collapseMode="parallax"
                android:layout_marginBottom="50dp"
                android:layout_gravity="bottom"
                app:layout_collapseParallaxMultiplier="-0.1"
                android:layout_height="wrap_content"/>



        </com.google.android.material.appbar.CollapsingToolbarLayout>



    </com.google.android.material.appbar.AppBarLayout>


    <!-- You can have list view here Instead of scrollview But you need to make sure layout behaviour is same-->

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorAccent"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:background="@color/colorAccent"
            android:layout_height="1000dp">


        </LinearLayout>

    </androidx.core.widget.NestedScrollView>



</androidx.coordinatorlayout.widget.CoordinatorLayout>

演示:

在此处输入图像描述

不要忘记玩东西

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM