Android动画将视图移动到另一个视图 [英] android animation move view to another view

查看:51
本文介绍了Android动画将视图移动到另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同布局的视图,我要将一个视图移动到另一个视图。我的代码有什么问题?Y动画播放错误。第一个视图位于片段布局中,第二个位于状态栏

    ...
    int p1[] = new int[2];
    int p2[] = new int[2];
    viewOne.getLocationInWindow(p1);
    viewTwo.getLocationInWindow(p2);


    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet
            .play(ObjectAnimator.ofFloat(expandedImageView, "X", p1[0], p2[0] - p1[0]))
            .with(ObjectAnimator.ofFloat(expandedImageView, "Y", p1[1], p2[1] - p1[1]))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale));

推荐答案

我为您提供了另一个解决方案:(将view1移动到view2)

 TranslateAnimation animation = new TranslateAnimation(0, viewTwo.getX()-viewOne.getX(),0 , viewTwo.getY()-viewOne.getY());
    animation.setRepeatMode(0);
    animation.setDuration(3000);
    animation.setFillAfter(true);
    viewOne.startAnimation(animation); 

这篇关于Android动画将视图移动到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆