Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: speeding up shared element transition between activities

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?

like image 643
Jon Avatar asked Jul 14 '15 12:07

Jon


People also ask

What is transition animation in Android?

Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.


1 Answers

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());
like image 179
Aleksandr Avatar answered Nov 01 '22 00:11

Aleksandr