package Ġgithub . inform ram iz . com . constraint set example Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . transition . Transition Manager Ċ import Ġandroid . widget . ImageView Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . constraint layout . widget . Constraint Layout Ċ import Ġandroidx . constraint layout . widget . Constraint Set Ċ import Ġkotlinx . android . synt hetic . main . activity _ main 1 .* Ċ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity () Ġ{ ĊĊĠĠĠ Ġprivate Ġvar Ġis Animation Applied Ġ= Ġfalse ĊĠĠĠ Ġprivate Ġval Ġconstraint Set 1 Ġ= ĠConstraint Set () ĊĠĠĠ Ġprivate Ġval Ġconstraint Set 2 Ġ= ĠConstraint Set () ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ main 1 ) ĊĠĠĠĠĠĠĠ Ġload Constraints () ĊĠĠĠĠĠĠĠ Ġregister Listeners () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġload Constraints () Ġ{ ĊĠĠĠĠĠĠĠ Ġconstraint Set 1 . clone ( root _ view ) ĊĠĠĠĠĠĠĠ Ġconstraint Set 2 . clone ( this , ĠR . layout . activity _ main 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġregister Listeners () Ġ{ ĊĠĠĠĠĠĠĠ ĠfindViewById < ImageView >( R . id . image _ view ). setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġanimate () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġanimate () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġroot Ġ= ĠfindViewById < Constraint Layout >( R . id . root _ view ) ĊĠĠĠĠĠĠĠ ĠTransition Manager . begin Delayed Transition ( root ) ĊĠĠĠĠĠĠĠ Ġval Ġconstraint Set Ġ= Ġif Ġ(! is Animation Applied ) Ġconstraint Set 2 Ġelse Ġconstraint Set 1 ĊĠĠĠĠĠĠĠ Ġconstraint Set . apply To ( root ) ĊĠĠĠĠĠĠĠ Ġis Animation Applied Ġ= Ġ! is Animation Applied ĊĠĠĠ Ġ} Ċ } Ċ