3

当我在一个容器中的两个组件之间切换时,我正在尝试使用新的属性动画来播放布局动画。

我简单地调用这段代码:

            public void onClick(View v) {

            if (componentOneVisible) {
                componentOne.setVisibility(View.GONE);
                componentTwo.setVisibility(View.VISIBLE);
            } else {

                componentTwo.setVisibility(View.GONE);
                componentOne.setVisibility(View.VISIBLE);
            }

            componentOneVisible = !componentOneVisible;
        }

我的动画设置如下:

    final ObjectAnimator testIn = ObjectAnimator.ofPropertyValuesHolder(
            componentContainer,
            PropertyValuesHolder.ofFloat("scaleX", 0, 1f),
            PropertyValuesHolder.ofFloat("scaleY", 0, 1f),
            PropertyValuesHolder.ofFloat("alpha", 0f, 1f));

    testIn.addListener(new AnimatorListenerAdapter() {
        public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setScaleX(1f);
            view.setScaleY(1f);
            view.setAlpha(1f);
        }
    });

    testIn.setDuration(3000);


    final ObjectAnimator testOut = ObjectAnimator.ofPropertyValuesHolder(
            componentContainer,
            PropertyValuesHolder.ofFloat("scaleX", 1f, 0),
            PropertyValuesHolder.ofFloat("scaleY", 1f, 0),
            PropertyValuesHolder.ofFloat("alpha", 1, 0f));


    testOut.setDuration(3000);

    testOut.addListener(new AnimatorListenerAdapter() {
        public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setScaleX(0f);
            view.setScaleY(0f);
            view.setAlpha(0f);
        }
    });




    mTransitioner.setAnimator(LayoutTransition.APPEARING, testIn);
    mTransitioner.setAnimator(LayoutTransition.DISAPPEARING, testOut);

    mTransitioner.setDuration(5000);

    mTransitioner.setDuration(LayoutTransition.APPEARING, 3000);
    mTransitioner.setDuration(LayoutTransition.DISAPPEARING, 3000);

由于某种原因,只有在切换组件时才会播放出现的动画。我希望看到的是首先看到消失的动画然后出现动画。

我也调用此代码来设置过渡器

mTransitioner = new LayoutTransition();
    componentContainer.setLayoutTransition(mTransitioner);

有任何想法吗?

4

0 回答 0