How can I programmatically translate an arbitrary view without using an animation (android.view.animation.*)?
API 11 introduced setTranslationX and setTranslationY, setX and setY, and getMatrix—all of which can be used to accomplish what I’m looking for. I cannot seem to find an equivalent on the prior API levels, however.
The android.view.animation.TranslateAnimation uses getMatrix in its implementation (as far back as API 4) but it was a private API throughout this time.
Is there any way to accomplish this without resorting to reflection?
Favorited because I would love to be proven wrong on this one, but I ran into a similar wall when doing some Drag-n-Drop investigations awhile back.
I’m pretty sure you’re stuck with
offsetTopAndBottom()andoffsetLeftAndRight()for moving aViewaround without an animation in early APIs. The big downside here is that these methods actually modify the top/bottom/left/right values, so you have to do some pretty heavy tracking if you want to go back to where you started from.Another option would be to simply use a
TranslateAnimationwith a VERY short duration and set tofillAfter…Other options require subclassing, and still aren’t pretty, like translating the
CanvastheViewdraws on. The problem here is you also have to create a parent that doesn’t clip it’s children so the view can draw outside its own bounds.