Raymond Chenon Raymond Chenon - 1 year ago 111
Android Question

Why Fade transition doesn't work on Shared Element

I have 2 Activities , the Shared Element transition works fine.ChangeBounds is the only the transition applied.

I want to apply a fade transition while the shared element moves, so the ordering is ORDERING_TOGETHER.

public class TransitionUtils {

public static Transition makeSharedElementEnterTransition(final Context context, final long duration) {
TransitionSet set = new TransitionSet();

Transition changeBounds = new ChangeBounds();

Transition fade = new Fade(Fade.OUT);

return set;


The startActivity calls ActivityOptions.makeSceneTransitionAnimation

In the EndActivity , the enter shared element transition is set

public class EndActivity extends Activity{
protected void onCreate(final Bundle savedInstanceState) {

Notes : I noticed that

  • Fade() is often applied to getWindow().setEnterTransition()

  • setting a
    duration to TransitionSet applies to all Transistions contained
    except Fade.

How to apply a Fade Transition to a sharedElement ?
What am I doing wrong ?

Answer Source

android.transition.Fade uses TransitionAlpha , which cannot be resolved in my IDE. android.transition.Fade works for enter and exit transition between activities.

So I created my own Fade to use Alpha. An Android view's opacity is set by alpha. And shared element uses View.

You call it like this :

Transition fadeOut = new FadeTransition(1f, 0f, new LinearInterpolator());

The full code is here

public class FadeTransition extends Transition {

    private static final String PROPNAME_BACKGROUND = "android:faderay:background";
    private static final String PROPNAME_TEXT_COLOR = "android:faderay:textColor";
    private static final String PROPNAME_ALPHA = "android:faderay:alpha";

    private float startAlpha;
    private float endAlpha;
    private TimeInterpolator timeInterpolator;

    public FadeTransition(final float startAlpha, final float endAlpha, final TimeInterpolator timeInterpolator) {
        this.startAlpha = startAlpha;
        this.endAlpha = endAlpha;
        this.timeInterpolator = timeInterpolator;

    public FadeTransition(final Context context, final AttributeSet attrs) {
        super(context, attrs);

    private void captureValues(final TransitionValues transitionValues) {
        transitionValues.values.put(PROPNAME_BACKGROUND, transitionValues.view.getBackground());
        transitionValues.values.put(PROPNAME_ALPHA, transitionValues.view.getAlpha());
        if (transitionValues.view instanceof TextView) {
            transitionValues.values.put(PROPNAME_TEXT_COLOR, ((TextView) transitionValues.view).getCurrentTextColor());

    public void captureStartValues(final TransitionValues transitionValues) {

    public void captureEndValues(final TransitionValues transitionValues) {

    public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
            final TransitionValues endValues) {

        TextView textView = (TextView) endValues.view;

        if (startAlpha != endAlpha) {

        ObjectAnimator fade = ObjectAnimator.ofFloat(textView, View.ALPHA, startAlpha, endAlpha);
        return fade;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download