Android setting pivot point for scale animation

2019-04-03 11:44发布

问题:

I am trying to scale views to a certain size but can't quite understand how pivoting works.

Say I want to scale the view upwards only. What value should the "pivotY" hold? In XML, it is a percentage. How is it when applying pivot point programmatically?

Example:

ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", scaleSize);
ObjectAnimator pivotY = ObjectAnimator.ofFloat(view, "pivotY", pivotPoint);

AnimatorSet set = new AnimatorSet();
set.PlayTogether(scaleY, pivotY);

回答1:

Quite simple actually.

If you want to scale upwards one clear option is:

 view.setPivotY(100);

and downwards:

 view.setPivotY(0);

then animate.



回答2:

Use:

view.setPivotY(view.getMeasuredHeight());

If you need to animate your object from the bottom.