1

So far all the tutorials I've seen online are about animating RecyclerView items on add/delete, but not the buttons/views inside the item itself.

The effect I'm going for is this: I click a button to download some content, and when it completes without errors, the button should slide out (or fade out or just move in any way) so that the user can't interact with it anymore.

Sample card inside a RecyclerView:

--------------------------
|       Some content     |
|                        |
| [Preview]   [Download] |      // <-- The Download button should go away, 
--------------------------      //     leaving the Preview button in the middle

I've tried android:animateLayoutChanges="true" in the item layout xml but it had no effect after setting the download button's visibility to View.GONE. In another attempt, I called viewHolder.button.animate().x(some_number) in the adapter, but it did nothing as well. Am I missing something? Or is there no easy way of going about this simple animation?

Please guide me.

Cezille07
  • 350
  • 1
  • 7
  • 17

1 Answers1

0

You can use ObjectAnimator for translation of objects.

http://developer.android.com/guide/topics/graphics/prop-animation.html

How to translate animation on an image diagonally?

Ex:

  ObjectAnimator translation = ObjectAnimator.ofFloat(buttonView, "translationX", 0);

  translation.setInterpolator(new DecelerateInterpolator());
  translation.setDuration(300);
  translation.start();

Change the value 0 to your wish.

Community
  • 1
  • 1
Nandhu
  • 68
  • 11