How can I programmatically translate an arbitrary view without using an animation (android.view.animation.*
)?
API 11 introduced setTranslationX
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()
and offsetLeftAndRight()
for moving a View
around 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 TranslateAnimation
with a VERY short duration and set to fillAfter
...
Other options require subclassing, and still aren't pretty, like translating the Canvas
the View
draws 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.