Search code examples
androidgoogle-mapsandroid-constraintlayout

Animating Google map in ConstraintLayout makes the app freeze


Recently, I started implementing CostraintLayout in my applications, and I have a map-based application that requires a map animation. Therefore, I used the powerful ConstraintSet to animate it, but when I try to remove an old constraint and connect a new one to the map the application freezes and gives me ANRs.

My code:

ConstraintSet set = new ConstraintSet();
set.clone(parent);

set.clear(R.id.detailView, ConstraintSet.TOP);
set.clear(R.id.map, ConstraintSet.BOTTOM);

set.connect(R.id.detailView, ConstraintSet.BOTTOM, R.id.parent, ConstraintSet.BOTTOM, 0);
set.connect(R.id.map, ConstraintSet.BOTTOM, R.id.detailView, ConstraintSet.TOP, 0);

AutoTransition trans = new AutoTransition();
trans.setDuration(500);
trans.setInterpolator(new LinearInterpolator());

TransitionManager.beginDelayedTransition(parent, trans);
set.applyTo(parent);

Note: Tested on Android 4.4.4


Solution

  • This is a bug fixed in google maps version 16.4.1