1

I want to add animations to my recyclerview, I tried using animateLayoutChanges but that crashes my app on startup, so i just changed my adapter and used this piece of code called in onBindViewHolder:

private static int lastPosition = -1;
    private void setAnimation(View v, int position){
        if( v == null ) {
            System.err.println("view is null. No animation");
            return;
        }
        if( position > lastPosition){

            TranslateAnimation translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0.0F, 1, 0.0F, 1, -1.0F, 1, 0.0F);
            translateAnimation.setDuration(300);
            v.startAnimation(translateAnimation);
            lastPosition = position;
        }
    }

This works, except some views start getting stuck in their position after i scroll. This is before I scroll(you can already see the first item is already stuck though) and after: https://i.stack.imgur.com/MiXgT.jpg . It's not only the first item that gets stuck, after I scroll a bit other items start getting stuck but I can't understand if there's a logic to it

Marco Cutecchia
  • 1,335
  • 2
  • 10
  • 14

0 Answers0