0

I recently switched to have a single activity (thanks to mortar & flow) which I then switch full screen views instead of starting new activities with the following code.

    setAnimation(direction, oldChild, newChild);

    // Out with the old, in with the new.
    if (oldChild != null) container.removeView(oldChild);
    container.addView(newChild);
}

protected void setAnimation(Flow.Direction direction, View oldChild, View newChild) {
    if (oldChild == null) return;

    int out = direction == Flow.Direction.FORWARD ? R.anim.slide_out_to_left : R.anim.slide_out_to_right;
    int in = direction == Flow.Direction.FORWARD ? R.anim.slide_in_from_right : R.anim.slide_in_from_left;

    oldChild.setAnimation(loadAnimation(context, out));
    newChild.setAnimation(loadAnimation(context, in));
}

This transition is exactly how I used to transition between activities

    activity.startActivity();
    activity.overridePendingTransition(R.anim.slide_in_from_right, R.anim.nudge_out_to_left);

To me both the view and activity transitions should render the same but what I am seeing is that there is something extra going on in the activity transition. There is some sort of fade out as well.

Anyone know how I can get views transitioning to look identical to 2 activities transitioning? I'd love to fully move to an approach of not needing more than one activity but would hate to have to lose the smoothness of the activity transitions

FriendlyMikhail
  • 2,857
  • 23
  • 39

2 Answers2

0

You can seperate your code in two activities instead of one. This is extremly helpful if you share only some static views (texts, images, ...) in the activities but do a lot more in the second acitivity. Sometimes it's a good solution if you use fragments instead of one view or two activities.

Please read in the docs about fragments and especially the fragment transition of shared elements. It is very easy to handle and keep your code clean.

Mann
  • 661
  • 5
  • 9
  • I'm trying to move away from fragments for reasons as described here: http://corner.squareup.com/2014/10/advocating-against-android-fragments.html. I was more asking how android transitions activities and if there's anything additional that is happening outside from the transition animation that is passed in. – FriendlyMikhail Jan 14 '15 at 18:48
  • What do you mean with outside? – Mann Jan 14 '15 at 18:56
  • I'm setting a view creation animation to be the same as an activity start animation with the following Yet when I view the transition, an activity seems to also fade out the old activity even if I don't do anything to create that transition effect. – FriendlyMikhail Jan 14 '15 at 19:02
0

You use two different out anomations in the code example. One time nudge_out, the other time slide_out. I don't know if its by accident. Maybe there is a global fade out for the activities?!

Mann
  • 661
  • 5
  • 9