Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
}
like image 776
Evan Dix Avatar asked Apr 22 '15 00:04

Evan Dix


2 Answers

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

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

TransitionManager.beginDelayedTransition(myLayout, autoTransition);
like image 99
linfaxin Avatar answered Sep 30 '22 16:09

linfaxin


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.

like image 22
dr_sulli Avatar answered Sep 30 '22 16:09

dr_sulli