Programmatically Translate View Pre-Honeycomb

后端 未结 7 1614
借酒劲吻你
借酒劲吻你 2021-01-30 00:09

How can I programmatically translate an arbitrary view without using an animation (android.view.animation.*)?

API 11 introduced setTranslationX

7条回答
  •  清酒与你
    2021-01-30 00:41

    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.

提交回复
热议问题