Bel*_*loo 10 java android android-animation android-layout android-recyclerview
当项目从可见屏幕边界外移动到可见点时,我想支持自定义LayoutManager中的预测动画.
我做的所有灌装操作onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state).
根据支持预先布局阶段(state.isPreLayout())的预测动画的文档,我应该设置更改动画的初始条件(例如,在某处放置出现的视图)
问题是我无法找到一种方法来确定预先布局哪些视图将从外部移动,因为我只能使用附加到RecyclerView视图的当前操作,并且在预布局阶段之后onItemsMoved(RecyclerView recyclerView, int from, int to, int itemCount)调用方法.(例如在预布局之前调用onItemsRemoved )
它是错误的,LayoutManager或者我可以在预先布局中以某种方式确定哪些视图将很快被移动?
PS:我能够保持从可见点到外部的预测动画,因为我能够遍历可见视图并确定recycler.convertPreLayoutPositionToPostLayout将要移动哪些视图.
//childViews is an iterable over RecyclerView items
for (View view : childViews) {
RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) view.getLayoutParams();
boolean probablyMovedFromScreen = false;
if (!lp.isItemRemoved()) {
//view won't be removed, but maybe it is moved offscreen
int pos = lp.getViewLayoutPosition();
//start view is a first visible view on screen
int lowestPosition = getPosition(startView);
int highestPosition = getPosition(endView);
pos = recycler.convertPreLayoutPositionToPostLayout(pos);
probablyMovedFromScreen = pos < lowestPosition || pos > highestPosition;
}
if (probablyMovedFromScreen) {
//okay this view is going to be moved
}
}
Run Code Online (Sandbox Code Playgroud)
这篇文章给了我很多帮助,但它也没有描述我需要的动画.
PPS:LinearLayoutManager也不支持此类动画.(只有简单的淡入动画)
您不知道哪些项目将可见,但您知道哪些项目将消失(或更改),因此基于此,您可以估计哪个方向需要多少空间。您可以检查 LinearLayoutManager 的代码以了解它是如何工作的。您还可以阅读这些有关 RecyclerView 系统详细信息的文章。
http://www.birbit.com/recyclerview-animations-part-1-how-animations-work http://www.birbit.com/recyclerview-animations-part-2-behind-the-scenes
| 归档时间: |
|
| 查看次数: |
699 次 |
| 最近记录: |