I am using Translate and scale animation. First i translate my Frame Layout to the center of the screen and i set its position parameters using layout parameters to the center of the screen. That works fine! On translate animation end i run the scale animation, my layout scales 2 times its original size. Actually my frame Layout (which I'm animating) consists of buttons and image views. As in android the animation doesn't transforms the view it only changes the position to which it must be drawn. Now my problem is that i cannot get my buttons to work. Because they are not actually there!
I found the solution for translate animation by setting its position parameters after animation end. Which moves the view to a new position permanently.
However in case of scale animation i have to change the SIZE of the Layout along with the child within. But it is not working as i am multiplying the original height width with the scaling factor. here is my code for the scale animation.
ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 2.0f, 1.0f,
2.0f, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnim.setDuration(600);
// scaleAnim.setFillEnabled(true);
scaleAnim.setFillAfter(true);
view.setAnimation(scaleAnim);
view.startAnimation(scaleAnim);
scaleAnim.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
FrameLayout.LayoutParams par = (FrameLayout.LayoutParams) view
.getLayoutParams();
par.height = view.getMeasuredHeight() * 2;
par.width = view.getMeasuredWidth() * 2;
view.setLayoutParams(par);
view.requestLayout();
}
});
p.s that setFillAfter(true) and setFillEnabled(true) are not the solution.
I would comment above but I don't have enough rep. This page from the documentation explains the difference between the view animation system and the property animation system. From this you can make ObjectAnimator and AnimatorSet objects which will move the buttons and edit the actual view, not just the drawing of the view.
http://developer.android.com/guide/topics/graphics/prop-animation.html#views
The property animation system allow streamlined animation of View objects and offers a few advantages over the view animation system. The view animation system transformed View objects by changing the way that they were drawn. This was handled in the container of each View, because the View itself had no properties to manipulate. This resulted in the View being animated, but caused no change in the View object itself. This led to behavior such as an object still existing in its original location, even though it was drawn on a different location on the screen. In Android 3.0, new properties and the corresponding getter and setter methods were added to eliminate this drawback.
The property animation system can animate Views on the screen by changing the actual properties in the View objects. In addition, Views also automatically call the invalidate() method to refresh the screen whenever its properties are changed.