Reputation: 1548
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);
Upvotes: 26
Views: 40274
Reputation: 807
Your pivot point takes your view as reference. So a pivot point set at 0,0 means it matches the top left side of your view.
So this animation:
ObjectAnimator.ofFloat(view, "scaleY", 1f, 0f)
Will be affected by pivotY
view.pivotY = 0 // will shrink the view towards the view top
view.pivotY = view.measuredHeight.toFloat() // will shrink the view towards the view bottom
view.resetPivot() // will shrink the view towards the center
In the same way, this animation:
ObjectAnimator.ofFloat(view, "scaleX", 1f, 0f)
Will be affected by pivotX
view.pivotX = 0 // will shrink the view towards the view left
view.pivotX = view.measuredHeight.toFloat() // will shrink the view towards the view right
view.resetPivot() // will shrink the view towards the center
Upvotes: 1
Reputation: 8138
Use:
view.setPivotY(view.getMeasuredHeight());
If you need to animate your object from the bottom.
Upvotes: 12
Reputation: 1548
Quite simple actually.
If you want to scale upwards one clear option is:
view.setPivotY(100);
and downwards:
view.setPivotY(0);
then animate.
Upvotes: 61