In this tutorial, we’ll be discussing and implementing RecyclerView Layout Animations in our Android Application.
在本教程中,我们将在Android应用程序中讨论和实现RecyclerView布局动画。
Android RecyclerView布局动画 (Android RecyclerView Layout Animations)
There are many ways to Animate rows in a RecyclerView.
Two commonly tried and tested ways are :
在RecyclerView中可以使用多种方法对行进行动画处理。
两种常用的经过测试的方法是:
- Using ItemAnimators. – Read this tutorial. 使用ItemAnimators。 – 阅读本教程 。
- Setting animation on each row in the
onBindViewHolderin the Adapter class 在Adapter类的onBindViewHolder中的每一行上设置动画
There’s another lesser-known but more efficient way of animating a RecyclerView using Layout Animations.
还有另一种鲜为人知但更有效的使用Layout Animations为RecyclerView设置动画的方法 。
We can directly pass the animation resource asset in the XML on the attribute android:layoutAnimation.
我们可以直接在属性android:layoutAnimation上以XML形式传递动画资源资产。
layoutAnimation is valid on all other layouts as well besides RecyclerView.
layoutAnimation在除RecyclerView之外的所有其他布局上均有效。
Let’s start by defining some basic Animations in the res | anim folder in our Android Studio Project.
让我们从在res | anim Android Studio项目中的res | anim文件夹。
down_to_up.xml
down_to_up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="https://schemas.android.com/apk/res/android"
android:duration="500">
<translate
android:fromYDelta="50%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="0" />
<alpha
android:fromAlpha="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toAlpha="1" />
</set>
up_to_down.xml
up_to_down.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="https://schemas.android.com/apk/res/android"
android:duration="500">
<translate
android:fromYDelta="-25%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="0" />
<alpha
android:fromAlpha="0"
android:interpolator="
这篇教程详细介绍了如何在Android应用中为RecyclerView实现布局动画,包括在XML和编程方式下设置布局动画,以及通过浮动操作按钮切换不同动画效果。文章还展示了相关代码实现,并指出对于GridLayoutManager,需要自定义RecyclerView来实现网格布局动画。
最低0.47元/天 解锁文章
5181

被折叠的 条评论
为什么被折叠?



