I was wondering, what's the correct way of implementing fade in/out animation for recyclerview items (onClick event) using MVP pattern.
Well, my approach was following:
- User touches item
[In my VIEW]
adapter.notifyItemChanged(position: Int)
onBindViewHolder()
reacts and this is where I set my animations:override fun itemSelected(selected: Boolean) { if (selected) { notSoSpecialView.visibility = View.GONE specialView.startAnimation(AnimationUtils.fadeIn()) specialView.visibility = View.VISIBLE } else { notSoSpecialView.visibility = View.VISIBLE specialView.startAnimation(AnimationUtils.fadeOut() specialView.visibility = View.GONE } }
Well, it works as I expect when Item is clicked - it fades out/in correctly, but, when I fastly scroll down/up, views get rebinded and now, every view calls itemSelected(false)
which makes unnecessary animations. How can I avoid this?
I did try to use specialView.clearAnimation()
, but that did not work.