0

I have a button (button1) and relative layout (rLayout). At start, rLayout is not visible to user. When the button is clicked, I want:

  1. if rLayout is invisible, it should slide in from the bottom of the screen,
  2. If rLayout is visible, it should slide back until it completely disappears below the bottom of the screen.

It should be something like SlidingDrawer but not the same thing.

I can do it with TranslateAnimation, AnimationListener and OnClickListener, BUT: my API version is 11 and I read that there are better ways to handle animation since api11. I tried to find examples of what I need, but failed to do so. So my question is: are animation techniques introduced in API 11 better that old ones and how to do what I need with those techniques?

Eugene Chumak
  • 3,272
  • 7
  • 34
  • 52

1 Answers1

2

are animation techniques introduced in API 11 better that old ones

My impression is that Google will be focusing on optimizing the new animator APIs (e.g., ViewPropertyAnimator) perhaps more than the legacy animation APIs (e.g., TranslateAnimation).

how to do what I need with those techniques?

Use ViewPropertyAnimator, with methods like translateYBy(). You get a ViewPropertyAnimator by calling animate() on a View, on API Level 11+. If you are supporting older devices, NineOldAndroids offers a near-workalike backport. Here is another SO question and answer that gets into the use of these APIs for sliding fragments around: https://stackoverflow.com/a/12318422/115145

You might also wish to read:

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Part 1 of the 1st article is exactly the thing I've been searching for. Btw, ViewPropertyAnimator was introduced in API12, so I used ObjectAnimator since my API version is 11. – Eugene Chumak Sep 12 '12 at 14:53