RecyclerView的人口动画 [英] Animated population of RecyclerView

查看:205
本文介绍了RecyclerView的人口动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个片段至极包含 RecyclerView 。基于文章中,我成功地创建所需的功能。

I Have a Fragment wich contains a RecyclerView. Based on this article i successfully created the desired functionality.

它看起来是这样的:

+------------------------------+
| +------------+ +------------+ |
| |   card 1   | |            | |
| +------------+ +------------+ |
| +------------+ +------------+ |
| |            | |            | |
| +------------+ +------------+ |
| +------------+ +------------+ |
| |            | |            | |
| +------------+ +------------+ |
| +------------+ +------------+ |
| |            | |   card N   | |
| +------------+ +------------+ |
+-------------------------------+

所有 CardView 在同一时间表示,符合市场预期。

All CardView are shown at the same time, as expected.

但我希望的是,意见逐一显示在视图外到它的正常位置。

But what I want is that the views are displayed one by one from outside the view up to it's normal position.

+-------------------------------+         +-------------------------------+
| +------------+                |         | +------------+ +------------+ |
| |   card 1   |                |         | |   card 1   | |   card 2   | |
| +------------+                |         | +------------+ +------------+ |
|                      ^        |         |                               |
|                      |        |         |                               |
|                      |        |         |                               |
|                      |        |         |                               |
|                      |        |         |       ^                       |
|                      |        |         |       |                       |
|                      |        |         |       |                       |
|                      |        |         |       |                       |
|                      |        |         |       |                       |
+----------------------|--------+         +-------|-----------------------+
                  ------------+             +------------+ 
                 |   card 2   |             |   card 3   |   
                 +------------+             +------------+    

任何人都知道如何做到这一点?

Anyone know how to do this?

推荐答案

创建自定义项动画(或者扩展默认的),并覆盖 animateAdd ,使得该卡将动画从屏幕下方。请参阅<一个href=\"https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemAnimator.html#animateAdd(android.support.v7.widget.RecyclerView.ViewHolder)\"相对=nofollow>有关详细信息,文档。未能正确地实现它可能会导致失去ViewHolders所以你要小心。

Create a custom item animator (or extend default one) and override animateAdd such that the card will animate from below the screen. See the documentation for details. Failing to implement it properly may cause losing ViewHolders so you should be careful.

运行动画的最好方法是创建一个动画,将动画 translationY recyclerView.getHeight() 0,您可以检查<一href=\"https://android.googlesource.com/platform/frameworks/support/+/master/v7/recyclerview/src/android/support/v7/widget/DefaultItemAnimator.java\"相对=nofollow> DefaultItemAnimator 为引用。

The best way to run the animation is to create an animator that will animate translationY from recyclerView.getHeight() to 0. You can check DefaultItemAnimator for references.

顺便说一下,在第一个布局传递,RecyclerView不会因为它看起来怪异的一切褪色动画视图。为了克服它,首先让你的适配器空与第一个布局后传中,添加您的物品(你可以使用一个处理程序,并推迟项目添加到您的适配器)。

Btw, in the first layout pass, RecyclerView will not animate Views because it looks weird to fade in everything. To overcome it, initially keep your adapter empty and after the first layout pass, add your items (you can use a handler and defer adding items to your adapter).

顺便说一句,RecyclerView不'没有'支持动画美景,一边滚动所以 animateAdd 时,同时列表是由用户滚动添加新项目将不会被调用。

Btw, RecyclerView does not 'yet' support animating views while scrolling so animateAdd will not be called when new items are added while list is scrolled by the user.

这篇关于RecyclerView的人口动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆