创建一个较慢的过渡。 TransitionManager.beginDelayedTransition();太快了

时间:2015-04-22 00:13:53

标签: java android animation transitions

我正在创建一个过渡。单击按钮时,将执行以下方法。该方法改变了图像视图的大小,位置,并将其淡化。我正在使用TransitionManager.beginDelayedTransition(); is too fast.来减缓过渡...但它仍然过快。我该怎么做才能减缓过渡期。谢谢。

private void moveIcon() {
    View moveableIcon = findViewById(R.id.moveableImageView);

    TransitionManager.beginDelayedTransition(myLayout);

    // change the position of the icon

    RelativeLayout.LayoutParams positionRule = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT ,

            RelativeLayout.LayoutParams.WRAP_CONTENT);
    positionRule.addRule(RelativeLayout.ALIGN_PARENT_TOP , RelativeLayout.TRUE);

    positionRule.addRule(RelativeLayout.ALIGN_PARENT_LEFT , RelativeLayout.TRUE);

    moveableIcon.setLayoutParams(positionRule);

    // change the size of the button

    ViewGroup.LayoutParams sizeRules = moveableIcon.getLayoutParams();
    sizeRules.width = 50;
    sizeRules.height = 50;
    moveableIcon.setLayoutParams(sizeRules);

    fadeOutAndHideImage(image);
}

private void fadeOutAndHideImage(final ImageView img)
{
    Animation fadeOut = new AlphaAnimation(1, 0);
    fadeOut.setInterpolator(new AccelerateInterpolator());
    fadeOut.setDuration(1000);

    fadeOut.setAnimationListener(new Animation.AnimationListener()
    {
        public void onAnimationEnd(Animation animation)
        {
            img.setVisibility(View.GONE);
        }
        public void onAnimationRepeat(Animation animation) {}
        public void onAnimationStart(Animation animation) {}
    });

    img.startAnimation(fadeOut);
}

1 个答案:

答案 0 :(得分:16)

尝试使用此方法:beginDelayedTransition(android.view.ViewGroup, android.transition.Transition)

AutoTransition autoTransition = new AutoTransition();
autoTransition.setDuration(3000);

TransitionManager.beginDelayedTransition(myLayout, autoTransition);