One of the task I was trying to achieve is moving a view from (0, 0) to (x, y) permanently with animation effect. Using TranslateAnimation is not good enough because it only draws the view in new location, but its actual position (invoked by getLayoutParams) is still in (0, 0). I tried attaching an AnimationListener and at the end of the animation and calling “view.setLayoutPararams” to (x, y), but it caused the view to quickly flash from (0, 0) to (x, y) at the end of the animation.
Finally I got this simple solution:
1 2 3 4 5 6 7 |
// first set the view's location to the end position view.setLayoutParams(...); // set to (x, y) // then animate the view translating from (0, 0) TranslationAnimation ta = new TranslateAnimation(-x, -y, 0, 0); ta.setDuration(1000); view.startAnimation(ta); |


Comments (13)