Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Animations and Transitions The Transitions Framework Create a Custom Transition

custom animation

I'm doing exactly as instructed in the video. Am I missing something? Steve Hunter

AlphaScale.java
public class AlphaScale extends Visibility {
    @Override
    public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
        return createAlphaScaleAnimator(view, 0, 1);
    }

    @Override
    public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
        return createAlphaScaleAnimator(view, 1, 0);
    }

    private Animator createAlphaScaleAnimator(View view, float fromScale, float toScale, float fromAlpha, float toAlpha) {
        AnimatorSet set = new AnimatorSet();
        ObjectAnimator x = ObjectAnimator.ofFloat(view, View.SCALE_X, fromScale, toScale);
        ObjectAnimator y = ObjectAnimator.ofFloat(view, View.SCALE_Y, fromScale, toScale);
        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, View.ALPHA, fromAlpha, toAlpha);
        set.playTogether(x, y, alpha);
        return set;
    }
}

2 Answers

Hi Mal,

Have a look at what the createAlphaScaleAnimator method needs to receive as arguments. It wants a View and four floats. Pass in those; the onAppear goes from zero to 1 for both the scale and alpha so that looks like:

    public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
        return createAlphaScaleAnimator(view, 0, 1, 0, 1);  // 5 arguments
    }

I hope that helps,

Steve.

thank you was also stuck here

Ok I see. A thousand thanks ;)