Wildblue09
Wildblue09

Reputation: 337

Creating a slower transition. TransitionManager.beginDelayedTransition(); is too fast

I am creating a transition. And when a button is clicked the following method is executed. The method changed the size , position of the image view, and it fades it out. I am using TransitionManager.beginDelayedTransition(); is too fast. to slow down the transition.. but it is still going too fast. What can i do to slow down the transition. Thank You.

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);
}

Upvotes: 12

Views: 10386

Answers (2)

linfaxin
linfaxin

Reputation: 431

Try to use this method: beginDelayedTransition(android.view.ViewGroup, android.transition.Transition)

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

TransitionManager.beginDelayedTransition(myLayout, autoTransition);

Upvotes: 39

dr_sulli
dr_sulli

Reputation: 903

Instead of using TransitionManager.beginDelayedTransition(myLayout); use TransitionManager.go().

The Transition that is most probably used by TransitionManager.beginDelayedTransition(myLayout); is ChangeBounds. You can set the duration of this ChangeBounds transition easily enough and then tell the TransitionManager to run it:

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

    // 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);

    ChangeBounds myTransition = new ChangeBounds();
    myTransition.setDuration(1000L);
    TransitionManager.go(new Scene(myLayout), myTransition);

    fadeOutAndHideImage(image);
}

Hope this helps.

Upvotes: 2

Related Questions