在Android中实现Teleport过渡

时间:2015-04-07 17:40:36

标签: android transition custom-transition

此问题涉及Transitions API。我正在使用 TransitionManager.beginDelayedTransition 。 由于我有几个观点改变位置,我想传送其中一些,因为移动它们并不好看。通过传送我的意思是,让它们生动地消失,然后再次出现在新的位置,也是生动的。 我已经覆盖可见性来修改视图的显示或消失方式,但我不知道如何覆盖 ChangeBounds (或任何其他类,如果更合适)视图消失并重新出现而不是移动。

此代码是我尝试过的,但它对视图没有任何作用。

@Override
    public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
        PropertyValuesHolder holderX = PropertyValuesHolder.ofFloat("scaleX", 1, 0);
        PropertyValuesHolder holderY = PropertyValuesHolder.ofFloat("scaleY", 1, 0);
        ValueAnimator disappear = ObjectAnimator.ofPropertyValuesHolder(holderX, holderY);
        holderX = PropertyValuesHolder.ofFloat("scaleX", 0, 1);
        holderY = PropertyValuesHolder.ofFloat("scaleY", 1, 1);
        ValueAnimator appear = ObjectAnimator.ofPropertyValuesHolder(holderX, holderY);

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playSequentially(disappear, appear);

        return animatorSet;
    }

返回显示或消失具有相同的结果:没有。

1 个答案:

答案 0 :(得分:0)

你快到了。您只需要淡出删除视图,然后将其添加回新的位置,并将淡入作为两个单独的事务(因为这正是您要求的发生)。