Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A view after an scale animation, have not resize to new position

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.

like image 463
user1519897 Avatar asked Nov 14 '22 02:11

user1519897


1 Answers

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.

like image 147
Drilon Kurti Avatar answered Nov 16 '22 03:11

Drilon Kurti