Reputation: 51
A view after an scale animation, have not resize to new position.
I using a android animation (ScaleAnimation) to make a layout(screen size when start) scale to 0.95 times size by itself and the scale reference the screen central point.
final AnimationListener al2 = new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
}
};
public void animScale(){
ScaleAnimation sa = new ScaleAnimation(1,0.95f,1,0.95f, topLayout.getMeasuredWidth()/2, topLayout.getMeasuredHeight()/2);
sa.setDuration(500);
sa.setFillEnabled(true);
sa.setFillAfter(true);
sa.setAnimationListener(al2);
topLayout.startAnimation(sa);
}
public void onCreate(Bundle savedInstanceState) {
scaleButton = (Button) findViewById(R.id.scaleButton);
scaleButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
animScale();
}
});
}
after this animation my layout have been changed to new position, but when i click again the button
the layout always from screen size scale to 0.95 times.
that show me the layout never change the actual size through the animation.
what code i need to add in the animation listener animation end?
i hope to achieve when i click the button it will do that, screen size -> screen size *0.95 -> screen size *0.95^2 ->........
thanks a lot.
Upvotes: 5
Views: 1853
Reputation: 514
ScaleAnimation doesn't changes layout's parameters. It animates without changing parameters for a smoother animation.
You can create a Boolean instance variable
Boolean animationDone = false;
and set it to true in onAnimationEnd
to indicate if the animation is done
public void onAnimationEnd(Animation arg0) {
animationDone=true;
}
and check it in animScale before animating to prevent multiple animations....
public void animScale(){
if ( animationDone ) return;
//..... animation code here...
}
Upvotes: 0
Reputation: 399
The problem occurs because you are using Animation
class. With Animation you only change the visible appearance.
In your case you need to use Animator
which also updates positions and dimensions.
The difference between Animation and Animator is explained in this question.
Upvotes: 1