23

我正在尝试将视图缩放到一定大小,但不太了解旋转的工作原理。

假设我只想向上缩放视图。“pivotY”应该保持什么价值?在 XML 中,它是一个百分比。以编程方式应用枢轴点时如何?

例子:

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

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

3 回答 3

59

其实很简单。

如果您想向上扩展,一个明确的选择是:

 view.setPivotY(100);

向下:

 view.setPivotY(0);

然后动画。

于 2013-06-10T21:10:01.057 回答
11

利用:

view.setPivotY(view.getMeasuredHeight());

如果您需要从底部为对象设置动画。

于 2017-04-20T07:05:01.473 回答
0

您的枢轴点将您的观点作为参考。因此,设置为 0,0 的枢轴点意味着它与视图的左上角相匹配。

所以这个动画:

ObjectAnimator.ofFloat(view, "scaleY", 1f, 0f)

会受到影响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

同样的,这个动画:

ObjectAnimator.ofFloat(view, "scaleX", 1f, 0f)

会受到影响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
于 2021-06-04T21:32:47.353 回答