Android: speeding up shared element transition between activities

Jon picture Jon · Jul 14, 2015 · Viewed 8.7k times · Source

I have a shared element transition between two activities that works in the following way:

Intent someintent = new Intent(this, someclass.class);

        if (Build.VERSION.SDK_INT >= 21) {

            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this
                    , new Pair<>(viewClicked.findViewById(R.id.someimage), "someimage")
                    , new Pair<>(viewClicked.findViewById(R.id.someicon), "someicon")
            );
            startActivity(someintent, options.toBundle());
        }
        else {
            startActivity(someintent);
        }

this works fine, but the transition is agonisingly slow. When the image is first clicked on it seems to stall for a second or two before the transition takes place. Is this due to the "weight" of the activity being loaded or is the delay configurable?

Answer

Aleksandr picture Aleksandr · Jul 14, 2015

Did you try change duration of enterTransition and returntransition:

    private Transition enterTransition() {
        ChangeBounds bounds = new ChangeBounds();
        bounds.setDuration(2000);

        return bounds;
    }

    private Transition returnTransition() {
        ChangeBounds bounds = new ChangeBounds();
        bounds.setInterpolator(new DecelerateInterpolator());
        bounds.setDuration(2000);

        return bounds;
    }

And in onCreate:

getWindow().setSharedElementEnterTransition(enterTransition());
getWindow().setSharedElementReturnTransition(returnTransition());