NineOldAndroids: set view pivot

早过忘川 提交于 2019-12-20 09:56:12

问题


I'm using the wonderful framework NineOldAndroids, but I can't find anything to set the pivot on my animated views. Specifically, I'm trying to do a scaleX + scaleY animation with a pivot on the top-left edge, so pivotX = 0 and pivotY = 0. On Honeycomb and beyond I would just set myView.setPivotX(0) and myView.setPivotY(0), but how to do it for pre-Honeycomb devices with NineOldAndroids? I tried the following:

AnimatorSet set = new AnimatorSet();
set.playTogether(
    ObjectAnimator.ofFloat(myView, "pivotX", -(myView.getWidth() / 2), -(myView.getWidth() / 2)),
    ObjectAnimator.ofFloat(myView, "pivotY", -(myView.getHeight() / 2), -(myView.getHeight() / 2)),
    ObjectAnimator.ofFloat(myView, "scaleX", 0, 1),
    ObjectAnimator.ofFloat(myView, "scaleY", 0, 1),
    ObjectAnimator.ofFloat(myView, "alpha", 0, 1)
);
set.setDuration(1000).start();

but it doesn't work, the pivot stays at the center of the view.

Can you help me please?

Thanks ;)


回答1:


Thanks to the author Jake Wharton, here is the solution:

AnimatorProxy.wrap(myView).setPivotX(0);

at any time, even after having called ObjectAnimator.start().




回答2:


AnimatorProxy.wrap(...) didn't have any effect in my case. However, the following line did the trick:

ViewHelper.setPivotY(myView, 0)


来源:https://stackoverflow.com/questions/9496074/nineoldandroids-set-view-pivot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!