1

I am trying to do a delete behavior like iOS7 in ListViews. i.e. clicking on a - sign and animate (translate) the row which contain the - sign to the left where a delete button will show. Then if the user clicks on another - sign on a different row, the old row will animate back to its original position and the newly clicked row will translate to left showing the delete button. Now, there is no problem doing this on rows showing on the screen but scrolling the list down or up, some random views that are NOT animated before are being translated to the right (the effect when canceling the delete). I know this is because of view recycling. I have tried so many times with saving position of opened (delete button is shown) row, setting tags to opened/closed, but there is no success, I still get un touched rows animated. I have missed around with the code so it won't reflect the problem if I post it :(, so please I would really appreciate any help.

P.S: I am using view.animate().translateXBy([width of delete button]) i.e. propertyAnimator.

Pradip
  • 3,189
  • 3
  • 22
  • 27

2 Answers2

1

before the animation starts tell the list view to not recycle the view

view.setHasTransientState(true);

and after

view.setHasTransientState(false);
Brian
  • 4,328
  • 13
  • 58
  • 103
1

A little bit late, but maybe this can help somebody, I'm actually doing this in the getView method and is working properly, this sample is to run multiple anims at once, but is still easy to modify it for a simple anim:

 private void translationY(View convertView) {
    ObjectAnimator anim1 = ObjectAnimator.ofFloat(convertView, View.TRANSLATION_Y, 400f, 0f);
    anim1.setDuration(TRANSLATION_Y_DURATION);

    ObjectAnimator anim2 = ObjectAnimator.ofFloat(convertView, View.ALPHA, 0f, 1f);
    anim2.setDuration(FADE_IN_DURATION);

    startAnimation(anim1, anim2);
}

private void startAnimation(Animator... items){
    AnimatorSet set = new AnimatorSet();
    set.playTogether(items);
    set.start();
}
LarryMustaine
  • 65
  • 1
  • 6