I am using RecyclerView and have some animation where I scaleup one of RelativeLayout in ViewHolder item.
Note: It is not the add/remove/insert animation. It starts when user interacts in ViewHolder item. Hence I am not using ItemAnimator here.
Animation works fine but it reappears (final state) in some random View item. I know it is due to reuse of items and I am clearing animation too but it didn't help.
@Override public void onBindViewHolder(ViewHolder viewHolder, int position) { Model model = getModelObject(position); ((Model) viewHolder.itemView).showItem(position); } I am doing this in showItem
relativeLayout.clearAnimation(); relativeLayout.setAnimation(null); In onViewDetachedFromWindow
@Override public void onViewDetachedFromWindow(ViewHolder holder) { ((ItemView) holder.itemView).clearAllAnimations(); super.onViewDetachedFromWindow(holder); } ClearAllAnimations
public void clearAllAnimations() { for (RelativeLayout layout : layoutArray) { optionLayout.clearAnimation(); optionLayout.setAnimation(null); } Here how I am animating the view
public AnimatorSet onDragStartAnimation(RelativeLayout group[]) { AnimatorSet big = new AnimatorSet(); for (RelativeLayout relativeLayout : group) { ObjectAnimator scaleXSmall = ObjectAnimator.ofFloat(relativeLayout, "scaleX", 1.0f, 0.85f); ObjectAnimator scaleYSmall = ObjectAnimator.ofFloat(relativeLayout, "scaleY", 1.0f, 0.85f); big.playTogether(scaleXSmall, scaleYSmall); } return big; } it is not working. RelativeLayout not resetting and appearing in scaledup state in some random View Item.
Update
I did small experiment: Set alpha animation on ImageView in ViewHolder item like this
Animation fadeInAnimation = AnimationUtils.loadAnimation(mContext, R.anim.fadein); imageView.startAnimation(fadeInAnimation); and used clear animation. imageView.clearAnimation(); it worked and ImageView was visible normal when next time ViewItem appears on the screen.
But same is not working if I do this
alphaAnimator = ObjectAnimator.ofFloat(centerImageView, "alpha", 1.0f, 0.5f); alphaAnimator.start(); And to clear this
alphaAnimator.removeAllListeners(); alphaAnimator.cancel(); alphaAnimator.end(); this didn't work. Alpha animation remains in ViewHolder image item.