package Ġcom . github . sat osh un . example . motion Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroidx . core . view . isVisible Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . view pager 2 . adapter . Fragment State Adapter Ċ import Ġcom . github . sat osh un . example . R Ċ import Ġcom . github . sat osh un . example . databinding . Material Motion Child Frag Binding Ċ import Ġcom . github . sat osh un . example . databinding . Material Motion Frag Binding Ċ import Ġcom . google . android . material . transition . Material Fade Through Ċ Ċ class ĠMaterial Motion Fragment Ġ: ĠFragment ( R . layout . material _ motion _ frag ) Ġ{ ĊĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠ Ġval Ġbinding Ġ= ĠMaterial Motion Frag Binding . bind ( view ) ĊĊĠĠĠ Ġwith ( binding . view pager ) Ġ{ ĊĠĠĠĠĠ Ġadapter Ġ= ĠChild Adapter ( this @ Material Motion Fragment ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġvar Ġcount Ġ= Ġ 1 ĊĠĠĠ Ġbinding . button . setOnClickListener Ġ{ ĊĠĠĠĠĠ Ġbinding . view pager . setCurrent Item ( count , Ġfalse ) ĊĠĠĠĠĠ Ġcount Ġ+= Ġ 1 ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ Ċ class ĠChild Adapter ( fragment : ĠFragment ) Ġ: ĠFragment State Adapter ( fragment ) Ġ{ ĊĠ Ġoverride Ġfun ĠgetItem Count (): ĠInt Ġ= Ġ 5 ĊĊĠ Ġoverride Ġfun Ġcreate Fragment ( position : ĠInt ): ĠFragment Ġ{ ĊĠĠĠ Ġreturn Ġwhen Ġ( position Ġ% Ġ 5 ) Ġ{ ĊĠĠĠĠĠ Ġelse Ġ-> ĠChild 1 Fragment (). apply Ġ{ Ġcount Ġ= Ġposition Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ Ċ class ĠChild 1 Fragment Ġ: ĠFragment ( R . layout . material _ motion _ child _ frag ) Ġ{ ĊĠ Ġvar Ġcount Ġ= Ġ 0 ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĊĠĠĠ Ġexit Transition Ġ= ĠMaterial Fade Through . create ( require Context ()). apply Ġ{ Ġduration Ġ= Ġ 1 0 0 0 0 L Ġ} ĊĠĠĠ Ġenter Transition Ġ= ĠMaterial Fade Through . create ( require Context ()). apply Ġ{ Ġduration Ġ= Ġ 1 0 0 0 0 L Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠ Ġval Ġbinding Ġ= ĠMaterial Motion Child Frag Binding . bind ( view ) ĊĊĠĠĠ Ġbinding . button . text Ġ= Ġcount . toString () ĊĊĠĠĠ Ġbinding . image . isVisible Ġ= Ġcount Ġ% Ġ 2 Ġ== Ġ 0 ĊĠ Ġ} Ċ } Ċ