【问题标题】:Getting scale and translation difference to animate transition from a view to another?获得比例和平移差异以动画从一个视图到另一个视图的过渡?
【发布时间】:2013-07-08 17:57:53
【问题描述】:

我正在尝试使用平移动画和缩放动画制作动画集,以使视图从其大小/位置移动到另一个视图大小/位置。

我尝试使用 getX/getY 或 getLocationOnScreen 获取位置以提供平移动画师,但在动画结束时第一个视图无法匹配第二个视图:/

(缩放动画相同)

有什么想法吗?

【问题讨论】:

  • 我快到了,但不知何故,翻译会影响比例尺的轴心,使视图有点“偏移”。

标签: android animation


【解决方案1】:

知道了...我的问题是我首先应用了平移动画,它弄乱了缩放动画的轴心点。

下面的代码示例仅在 X 上翻译。

View viewFrom = findViewById(R.id.viewA);
View viewTo = findViewById(R.id.viewB);
// Getting delta from center
int delta = (viewTo.getLeft()+Math.round(viewTo.getWidth()*viewTo.getScaleX()))-(viewFrom.getLeft()+Math.round(viewFrom.getWidth()+viewFrom.getScaleX()));
float ratio = viewTo.getScaleX() / viewFrom.getScaleX();
Animation anim = new ScaleAnimation(1.f, ratio, 1.f, ratio, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
AnimationSet animSet = new AnimationSet(true);
animSet.setInterpolator(new DecelerateInterpolator());
animSet.addAnimation(anim);
anim = new TranslateAnimation(0, delta, 0, 0);
animSet.addAnimation(anim);
animSet.setDuration(500);
viewFrom.startAnimation(animSet);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-27
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多