[英]Animation in recyclerview item by item
I need to implement animations in RecyclerView which has a slide up effect for every item. 我需要在RecyclerView中实现动画,这对每个项目都具有滑动效果。 I have searched for this and tried many different things.
我已经搜索过此内容并尝试了许多不同的方法。 It works when you scroll but it is not working when the page loads for the first time.
滚动时可以使用,但是第一次加载页面时则不能使用。 I have uploaded a video on this link.
我在此链接上上传了一个视频。
I have tried this code 我已经尝试过此代码
@Override
public void onBindViewHolder(ViewHolderHelper holder, int position, List<Object> payloads) {
super.onBindViewHolder(holder, position, payloads);
setAnimation(holder.itemView, position);
}
private void setAnimation(View viewToAnimate, int position) {
if (position > lastPosition) {
Animation animation = AnimationUtils.loadAnimation(mcontext, R.anim.slide_in_bottom_list_item);
animation.setInterpolator(new AccelerateInterpolator());
viewToAnimate.startAnimation(animation);
lastPosition = position;
}
}
Also tried 也尝试过
animation.setStartOffset(position * 100);
but that is missing an item on fast scrolling 但这缺少快速滚动项
Can anyone help me ? 谁能帮我 ?
After searching on internet i decided to do a hacky solution. 在互联网上搜索后,我决定做一个hacky解决方案。
animation.setStartOffset(position * 100);
Many post has this suggestion. 许多职位都有这个建议。 But this is messing when you scroll fast in the recyclerview.
但是,当您在recyclerview中快速滚动时,这很混乱。
So i decided to do this offset for onlt first few visible items and then animation applies to other rows correctly without offset. 因此,我决定先对一些可见项进行此偏移,然后将动画正确地应用于其他行而没有偏移。
@Override public void onBindViewHolder(ViewHolderHelper holder, int position, List<Object> payloads) { super.onBindViewHolder(holder, position, payloads); setAnimation(holder.itemView, position); } private void setAnimation(View viewToAnimate, int position) { if (position > lastPosition) { Animation animation = AnimationUtils.loadAnimation(mcontext, R.anim.slide_in_bottom_list_item); animation.setInterpolator(new DecelerateInterpolator()); if(position < 4) animation.setStartOffset(position * 200); viewToAnimate.startAnimation(animation); lastPosition = position; } }
Hope this helps someone. 希望这对某人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.