Programmatically Translate View Pre-Honeycomb

后端 未结 7 1789
借酒劲吻你
借酒劲吻你 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:46

    Yes, you can use TranslateAnimation. With fillAfter set to true your view will stay translated even after the animation ends. Here is an example:

    TranslateAnimation anim=new TranslateAnimation(0, 0, 20, 20);
    anim.setFillAfter(true);
    anim.setDuration(0);
    yourView.startAnimation(anim);
    

提交回复
热议问题