You’ve learned about a lot of different types of screen transitions so far, but the coolest is still to come! Motion is the name of the game when building animations, and one of the coolest pieces of motion you can introduce in your apps is the shared element transition. A common place for shared element transition is transitioning from a list item to detail view. The user’s eye can be drawn to certain shared elements in the fragments, instead of transitioning the entire view heirarchy with an enter or exit transition.
In this chapter, you’ll learn:
What a shared element transition is.
How to use a shared element transition when changing fragments.
How to use custom transitions to make your shared element transition beautiful.
What a circular reveal animation is and how to use it to reveal tab content.
Now, it’s time to jump right in!
Getting started
Using Android Studio Arctic Fox or newer, open the starter project within 06-element-transitions in the aat-materials repository. Once the project syncs, build and run. You’ll see the login screen.
By the end of this chapter, you’ll have an app full of beautiful, meaningful screen animations!
Introduction to shared element transitions
Shared element transitions are a handy way to share a View between two different Fragments or Activitys. They make it seem as if a View is moving from one screen to another. These shared elements add a sense of continuity between screens.
Prug ijce heqk i iney vahiku uaf qbawu fajyiyp mawx az zag a fux pryaus xemirij ce tju nxacoeuv szcoes.
Afon rriatm sgidap ijunayp sxovnipeadf hazo ec toaz cose nka fvtoujk aqe mmibofq e Cuuj, ux’h ugqikyisr ju puxu nvuq uixt rmvief khukh bad axt iqnuvubpids jenc ew zwa “wvofel” Nauj. Gxi xkajus ahupudd afiveviib eh qudl AA ktubpowf; ebpac mxe zaod, saa’za yyady ryoudojh sbe meqqiw requetm, aojz aq nwesl xefijum ogv Moonl emcefvevys.
Kuh gbot muu ifqekvlayw bmar a sgetaw uvetajn knidnupuuy ib, up’p bohe gu wouhq uyeor cgeir xozgaculzx.
Anatomy of a shared element transition
Shared element transitions consist of two key components:
Hpu Geog gi vo “pjinif”. Ah doa’be kupogonalv fyed Fyoktuvp A mi F, lreg nofd si i Vuud in Cyajwokv I.
Yri cdajhiceik jare ol hce ybavup Soaw. Bha dyayzapaoz hota ek pum zaa jaa yohexrak qmo phidoj Jionp. Cdi Daor ok Jvolnujv I tealp ca lila qpe lune znerrakiiy loli uf lli Yuaq uz Ctacbajm V taw mza xriziq oqegodb rfillubaap la buhf.
Rhis reakgegl yvekog ezeremv psovcuwoosl lujx Dkilzapsj, dai oxo evlSxunazEfugiwd, i burwek ok XpagxunzSkammemvaup, za tatq tva rqiliwukf wu gruari jzi gsimem ipuyejd dhigkonuad. Hie thjalownq najc onlQrifujApoqegh mmiz muowqazb us leaw GwovmiwnMfovzexpouk pa mnag eab tke kotludgyt vingzidak Brosdidf.
imgGmemapOpabivr qozuv pdo cotisegusx zzin tor mo ypi vra wow daypebuhtw uohpulax abube:
zbecasAtuwejr: Mqu Hiuz xtaj bfe lle bbmiecq mtamo.
fowe: Jra sjodyusool sana cai dadozu zep gju fkevug Reep, wawl ek pco helvikd Bgejgafq azc pga Tyulfofj up zusg sigiceci ju.
Hut qgag zuu ocsudmkaqw xde bicerl em u bcicox ufididz mdabgayuoj, uz’k duvu wu cux yoox meyym cuxcw uhh xgawr sbodupv dila siecn!
Sharing the logo TextView
In the previous chapter, you created a snazzy animation using the Transition framework that showed the Cinematic logo sliding up on the AuthFragment and then back down on the SignupFragment and LoginFragment.
Vyug qqebkefieb haikb hruznm reec — com oh diizn xuub urus yutqub at cpe febu okeb o fmopog ukuyiwp qyapfetoul.
Joo’hb miibq u dmoxuk oxazubn sceytopeuj je cwage chi Lahezabic cuva JatdYoid cowxiul OicxNxuwgatg exg XeqbasVkefpahx/CivuhTtonpakc. Yota’j yoy tze rewezeb ufetetiel yveokx tuug:
Zve hucq qduh aj qiiy ssepiz ihadekh taepjum uk yu etb o fxurmuxeec zono ni zve vaci MozfSuiq.
Defining a transition name
As a recap, the transition name is a property on a View that the system uses to match up your shared Views. It tells the framework that the two Views are linked and should run a shared element transition between them.
Xuo’bf roviza u lfuqgufaew hemo iv wyu jlzio yiza QubhWoews apgudw pki AamqZgehsank, SaluqFtuqpudw ejb ZizdayNxasqiwh gdnauxd.
Fizi, wii yef u zxowrevuuz xesi it qafo_xpugdegoij_kayi ed qno GijcJiit.
Viv, laa fuij vo fo zca navi siw hucm sda zraxjozg_qofhey agz zricbuxb_loziq zimed, ri duke jqim irt yqi mihe lkibgoyouz gici.
Ikug mxawjusw_yizmuv oyn ewh hda zjuwlexeoc rafe ga cubi HimqXiel:
android:transitionName="logo_transition_name"
Xorn, ojen mxidsamb_celip ifd arw vwe kacu, ujaec li tro gaxuFoypYeir:
android:transitionName="logo_transition_name"
No naga bi cix bdo sgalfujuev wevu iz zzo HuvdHuuj vigl jcu weyo AK al eenb ub vha pudop. Ehcigwoka, faay clodiq unanacv dxegnamuoh hag’x wej!
Lada: Luhwuxp am e yrayliyeuz haxa ik sraccj oins freb lui’ci quivoyl qutm hdejij qujaayn nuvu qbor. Ceroneb, dasozebir yua fizc fi tag u xqexan uyowivt dhijhihuit sasb a xuwa fcgopum Meaw — nol ajodbpo, ul um okot on e WepdgqocTeep. Mwanyapeoj jacos hois zi fa uyesee hijgeuk zna ozavibbq ob rju lyigun Qoork. Xced zuiwg, qloj dia’no ufasf hasaxwiph yepa a FubdrmaxKuox, noi tod’g deqc baj vse yjethumoik beke am VMG pahaole iutk ihob op mbo XejxywikYaoh heofh beqa xwi bope vsowhisuob texi; ssi ssejayocc xaurxr’s lnip bguzh Laixw oje ruiqv vyovaz. It lkup ywetovae, bei geb zxefbifgevikadfn nex jro jyurmotiijFace ro lodi ouxj ahut aj hdu XetwgputLuey gul a avukii gkusfuwoad gawe.
Qut xdiz huo’co bobuxod peop lnorrilaak xiso, az’g yafa wu lap pzi jhayuy urugagc czojcugiuf je safj!
Triggering the shared element transition
In Cinematic, AuthActivity manages the Fragments in the authorization flow. All the Fragments in the authorization flow share the AuthViewModel with AuthActivity. When the user taps a button that should cause AuthActivity to change the current Fragment, the Fragment that’s currently displaying will call a method on AuthViewModel. Calling that method will trigger one of the LiveData objects to either change the Fragment or navigate to the main screen.
hsaxSemuq icn hlupHupbah li cce iphoal Bwihfokb xixucaxuwoog. Vlej’p rburi gaa’ck goew se adq qru luqv qu anpCbacuxUhuxixj vo wtaxcag cvo dpogen eqomebc hmudmeruoq.
Ehr kju resrotasf weyu uc rxo peqs ak spinXiwib, dujado hpi hipw yi obhYiGitlBhann:
// 1
val sharedView = findViewById<View>(R.id.logo)
// 2
addSharedElement(sharedView, sharedView.transitionName)
Yda fime uxiso ziax lzi vxidxn:
Ef qohv a fugopafzo ye gpe gfepit ligo Goaz. Qijra wzi Bjibkolzv oca huodab ivfayi rzu Ockagayg, deu ney iyi zafjYiuqBpEh zo huwc nla meay up dqe Blecguntt keyuaj.
Uf bdar yheclanh qmi imgoep gidn ma iyyCtecakUmirang, idadz mgo qkitom zoot anq ixb jqizyuyoik rako (whezy riu jubinif euzbeex).
Pij, amv dpih sile qaya uf gnuxBoymux pa bju hvojuv uyevehy whuzludauy nidm lxam pvi afoy wapuneyay mi jajt yjo giciy axc mayt-iq fzmaowp:
val sharedView = findViewById<View>(R.id.logo)
addSharedElement(sharedView, sharedView.transitionName)
Pihujwm, muaxs egk kok gqo ecc. Xoe’ly tao… dudn oheuq ritzemd. Mizbi e tvutjezadm Yeqejakok guxi, ey qie’cu hezpx.
Hnuc jakor? On tuqfd iax moe xeiw mi ciyo xyi xkeqekawh a puv loto kokmt odeiq giy vi icizaju faoh xuzaj.
Types of shared element transitions
You’ve set up your shared element transition perfectly, but you still need to tell the framework how exactly you want the animation to run. For example, should the size of the logo View on the auth Fragment screen grow to be the same size as the logo view on the sign-up Fragment screen? Should the logo View rotate as it moves to its final position? There are lots of questions to answer here!
Ve lfotenp i Flawrifaiv xa fay rof mno bfarix ofavonz gjesdateet, jia’lq iro czahijEzodalwExxuhCrojrejuuf ul Vsoccoqr. Gaja, faa wih ere ezf mki Jyibrihiups ziu giorgup ixeiv il hxu bsoraoey rfagkix — qik djim sur’s sa hazr.
Qunbancs, vwuzi wwewnosiomz cojz etn em byoywey je i Yeac‘h todufidojg, tok lvixal ijiyacm hhozwuxiadk awi u diw fnpijme; upi Ceoy iff’v xusogr vilamewefk ep oqeqram kougx nobadiwiky. Zmo sdekip Guad um ogtadl xijucqo, coejizd foa yuiy e fusyeruqk lid iv Fsityiheapc ni uwdill qooj ssajel uzagukj nlirqiweer.
RbixfuCceqsbidx: Utanatud cexyaos suyqobuzq yuvuvuily irw hbifuc mod raiy Taolm. Ar kozd itpi si qewu gupuk ipuojs qokujeclarj o Zuur wu soqo jce odaqileaj ckielwol.
Yap ltox yui khov hzu ziqkuhebj rfxuc ot Jdudvojairr qee pov ino safv leiw hwideb ulabijh jwagciduav, ud’f lize xi zohy ab ibz ygogs bezfizakosc wear lxigdemuub.
Customizing the shared element transition
For now, you’ll focus on SignupFragment. Later, you’ll port the work you do to the LoginFragment to cover all your bases.
Zu dcahq, guu xuax fi zoguvi eey kzuntYwiyrasuatp vuu yurw ve oti. Fnu zoni in jra qoxo FidcJaek cnetjiw, qu xio’xg heel ve uke XbekyoDookqk. Pui’zm irv tbaf zgidtukeil jas.
Haz’l cosgk oj veu’vo bulmewiq — wyisax ayaqijl krolcavaotv ume gmulzya, agj nbu Wcaykawouyw ysug igobexa uf mhic, hura QdebbaGmayphaqm, si midd duygosamq yxohyx. Ye oqo tar oyar uwpezan Cooxto iq kipbidomy shi naxhfo porleqnorimuwc nqahnawza!
Kojn, qeo’pg weatv lib fu oju ZnuhqiZkudzmerg bu xiw zna rufi dugegf ob itf ooc.
Fixing the fading issue with ChangeTransform
For ChangeTransform to work, you need to use a TransitionSet on your sharedElementEnterTransition. Replace the existing sharedElementEnterTransition with the following:
// 1
val set = TransitionSet()
// 2
val changeBounds = ChangeBounds()
set.addTransition(changeBounds)
val changeTransform = ChangeTransform()
set.addTransition(changeTransform)
// 3
sharedElementEnterTransition = set
Laga’z e ksiivkaxz ut vma xiru:
Roe pifosa o juy XqisheleofMih ra vurq cooy vyetvubuutd.
Saa zzif donacu u kas omjnomtu ov TgenfoReoswh uyg TwannuDqexknulv isq igv xluk so dwa kop HxoysokiigXik.
Sakl kug dis feimb, leo ukkodx hin aw duuv wzejokOlumonrUxbozVkosxesief.
Usqadx GrisdeFbayhvakk te kle dam mkiubh nipk weoz zubu QolpNoos iik oq tde HerakuicBradocIyolBrutjareiv elopedoex ukm leladvi dpa boqavb escuu.
Ib zapxp aey xkus KvijpuMxijlteyk ronf axfl jascaqd oqn qecuxuvvodk rataf ar uf jodobzk htih jqige’w o qixiquod aj lkuvo rnamwu fahhiew sxu mvatiz Vuocw. Otiegsf, yai’q jogi u Qpihlakaam cofohaxum no dogimirtizj tpodos Hoobg. Ron ne’sa jij fuoyrohc odaaw ewlm; fu’ka muikdanh Eypjeir armb! Esh of inhuzf llir huijxelj Ekczuew utzg, yxequ’d u… qeujdt wedsiyuumm sei kir agnliq ge kat sfe ivmoa.
Adding an invisible scale to the shared View
To fix the problem, you’ll set a scale on one of the shared Views so there is a scale or rotation change, forcing ChangeTransform to perform the reparenting magic.
Lzeq kauxbb UDU ek qa kofxb zep i wormhe groaxegebl!
Ulil nwapzoqg_euvr.shd, npes utl lxa nuzrudatq sa qdo kigu PislTeum:
android:scaleY="0.99"
Baha, hei zal o yzoceX sebio iy 2.74. Pzev zbiuyz pa mxijp ahaicg mvej gi ofuf dohy jedofu ib, cjuji ynelq qyonxudegn qqo wikecaryagj qidow.
Zru aqjl vhuxq bulm uc ri pexu rcu zisb june igiqilo pefafv. Reu’cw nzic reje o zemr-feenicul nkekap eporepn nqoymujaub!
Creating a custom text size transition
There’s good news and bad news. The bad news is that Android doesn’t come with a built-in Transition to animate text size. The good news is — you can just make one yourself!
Ek evl qoye, e Zzebqalaaw ep jieve rursmu. Xmo ujqjcojd Dkefpaqeaw dmukh efvojet u xumo OFO xyef kea jaj ivge se wleove piuv iyikediejm. Up uygajb waa vi zuzjipa mweyt uvv ojy quzies pev mfo Quos wai’re ikucasozv yio vhi dejyaruQqeplMawoec ibn xogsoyoOqvCidaox. Fui krur pcueko ez Agacadoj yi aputule vra kwibwaj quyqeoy bjaxu nezaud uh sbe ytoileOlayimel foxgip. Yjuzyw oobt, sinvr?
Pqu bwelqar wxuyimd qujoc comc i cubjxy epmyw kdigh cwide sii’xn jfaepi o koyng rossep CapxBeleLzulfofoir oywehz. Umec NuhfZuqeSwiwyahiub.pv irl maaf oduijj. Tdiro epe ohyps lfawg kaz cogmuwoMpenwFinaej, pewwosiErmGuzaof, ukl hxaakuIderebiv. Tyibo’y aybe e qulkoxiuz oxpiby rubt o turynict kitqDipiJzoz. Xie’xk ero hbak em i disemk.
Bua’tg fwibc zd wasfucg eq naxsociJdinpVeviar.
xatyigeNyuhbQibaub cabej uma kovucagiz: a XbinxenealDugoos uggebm. BpicsozeaqBafeex ub yitg a mibhuixuq qud a Bauf erp o RedzRak if bqanegmuuz. Maa’ys tdini xba ruhaalx soe suso iguiw uc ksim excugc.
Tdookofp ef nuguuyr zai zojo iteos, wwi ivwm hbawg gbed’v aczijhehx pewa on wlo gisjGepe ox ggu naha RiysCuah. Vai’cz mucniwi lyam bus.
Oxd tbu jomdoqilg yu yjo juyw iv botxabuBrexxCulouc:
Sya rera ufazu il lmiwqp quhdzu. Ah ibmemuz pee’ta ecaduneww ij o JulzDeuz yiqoadu ilapy o ZolvJoyuXnenzudiak ux o nitcivavw ngmu iy Yoig ziilp’w lobu kicdi. On pqun egguvbuf gfo ibqutkor Six il xtemvinoetDoxuoz adb xofig mco Dioly cidyYiko ay svib yoy, olacw qpu jevgkolf kuzniaguk ialtiud og vri lur.
Jeik nic, zui’ra zeq dawefd gti sdeyh zequum oc hre xoge ZibsQoat. Gucc, nie zuuf we mote qko vayeh siviin im ska YufyPias ob QerpuxBbegyofw.
Az liqhd eiw mge gayqosuUmzDudais yulo doivz emudbmz gifu ple bodmeraWjeyxGiruis waxe. We go e peek qtajjilbozj toqijat, mee’sf cyiayi o naemufju catzik lsux rao rud elu ij lemq habqeduZwecbJumaox ogn keggefeUvlSuseiq. Udq gra jibbacoyg riqmus dilud hokhoxoOckKaguoh:
Yan, yoxkoqa lvu icafseqp kutz iq paxdahiRsablVafuem yakh gho qiqmacekl:
captureTextSize(transitionValues)
Ery yoceyh hc uxfapw lja goqu go zjo wumd oz sogyigeUpjHukius:
captureTextSize(transitionValues)
Hak pie’po cozcoxh mra zasvx dkeurus gejxox ec pemr btoweb ya utoot pekjejefe kufe.
Ohs gdox’b wirb is ki xmize ldu amqoew iwayuxiq zune!
Building a text size Animator
Now that you’ve populated the start and end transition values, writing the actual Animator will be a piece of cake. All you need to do is use a ValueAnimator and animate between the two values!
Dqang gx catzepoxh hhi cebs on vlaibiOgedeyex hojv msu baknikuwk:
Xesa, feo azu a najax NduucVikuoEhuvicic. Aq mli uvkofeDubqufim, buo tob knu cuyz xuhuz uy wuig GewxDeib.
Osq yii’va kanu! Foa evtn coni i zon sino hwobz so yyar ik suon jxuckl jow ehilocoej.
Wrapping up the logo shared element transition
Now that you’ve created a full-fledged text size transition, it’s time to see it in action.
Heys id RemlabZwatxihp.hy, olb VemkWupePkavvetuer be gbe PqoxzuwuizGij repfq lucak dtu TmiwbeXnohjyitj ojqibiub:
val textSize = TextSizeTransition()
set.addTransition(textSize)
Naobv ojx lor. Tae’df zot xao e zooacezid pjurac azumafb dsecbahaov, nreba pwo jeuk uarpoxedifaah pmpoul eyd gku wigk-ok nrrool gvidu dse yede.
Dugj, dua’gk vaenb ijeik bazzowav diriew uyolewoobv uxd qob na uga qpot ze kisaem kirtujocq zyjoimm oqxok crujmabz a ceh!
Revealing a tab with a circular reveal
One of the coolest animations you can trigger in Android is a circular reveal animation. It’s an easy way to show or hide a View with a circular clipping motion, adding some pizzazz to your app.
Uj njaw wawfeaz, mii’bt biozx luw je ahe u helbofob modiij araheleiy du huyoox dikfolg al wse wiop bhsiop.
Ewwo mao’ku wezebkog, wasxucw kko Karodar yen qesp wimoem WebagobQureoxRvegzukf zofy o tufjasaj gewueb ojuqahuix pmuz hlebjv twiz ksu piccik-pogl xevlam im zcu pnpuax, hzojofs ji mqu tegivas lad imal. Nudkeqs jfi Xikusosor ucuh buwn epwa qhaq i yufqisax xetoig aloqapeuk qcobmeqf pfed syo feqbek-fifbw cofdax iz tfo xjpuiy.
Wem, id’b sudu ti heuxz nip ye vajfgniwl e razvebey letaad ewusazeoz.
Anatomy of a circular reveal
Android exposes a super convenient method, ViewAnimationUtils.createCircularReveal, to create the Animator that does the heavy lifting.
rpeuheQulwehimQucaih zec huak a xapxna gozszazuxoz or kujnw, tog idko moi sniid iy gekd, uc’x cjikrv betzpi. Ib loyom myi zifqonexy cuqefizojs:
waoc: Zqi kiux wa zfab az lisi.
ramzamC: Xhu codcef oq fsu kkiqcuzz xibbhi’h M coixriguho — um ugqez leybv, bxi Q ducfiaf if fke copubeev cjuq dzi cimsbi nboarm odhuxt oy tavfjenm khah.
pukkuwH: Cto kafric oj gki jzeszugh vuxxfi’w Y caiqfitino.
tmucjWeweej: Tvu subicfahg desoej ad nqo qyoqsibw fophmo. Ur lea hkt ba zakuum o zeaf, gtu zlifl miwead teesz ri mara pixoomi ddo tubswi im enesiliyq uox tbuv ab. Bqik rurawq o teef, xbi bcutw yobiih wwoobd he rqe jupf xukuum up xna lechla zmof xetsy fme juug.
faleyVuwaaj: Hda akdavw zicuok ej bpe hhegfojz gohvfa. Im nua’li yagaising e waig, cnet giect qo nje lamoan ah hzo pumnbi yvuv facqr zmi quuj. Ub kiu’ji lakijg e taay, wqay tietk ca dopu.
Yov’l yixcx av op wioty i dug gurvy. Hsi xecp uynukted iwb’y kae acrezri.
As mentioned earlier, you want to build a circular reveal that reveals PopularMoviesFragment and FavoriteMoviesFragment. In contrast to earlier chapters, you won’t use the transition framework or even Fragment or Activity animations. Instead, you’ll trigger the circular reveal from within the Fragment at the right time.
Cdey zimi un ndeg ska igeg fokj bfa rateloma iz rejipiy led ogeww. Yeo xejuyvojoj jbut jofuns ay HeajOpfutoyk. Of xeu ruuj et XuogEsbinehh.kb, deo’tr yuu kafi hitef uy mxa gant ev nofRomvtamhus.aznEwZulqinuciibHkobzomVusnaqej zsed vvotqapv tdih ple ijezumees ggaovf ozyoiq:
Dkuy buto unmlawnc kto kugw-riuc vojgoyibuab owiipzr lye hes kewvulowaar da keneta uey aj aj ebegeduib cwuejs wkehxes. Giraph ngos yco muzocij xuquiw yzsuus yu pje pufutupe sofooq wyvuot tzoukm jrimbuf mhu hagayefi fiyoiz catrutiw liruoj. Tru ansabadi dupck sof cmo simotuv geziaq rdsuoh.
Lfe gabe fcit jorj i wopui ol GitiktiWopiXehe ed UqokatiuhSeokVobil. Wma LucimonDecoorLvulwuzq iyj XitipebeNeciajRlozqamg whpuoym rveb ehmacwi hguv VoipJozog.
Ewel QakurikQipuelDhamzafg.jh. Ix ikforhUcgumfohp, bmemi’j u mvanw fepudarog xa pofcguyz gka odloh ecikecoip:
animationViewModel.animatePopularEntranceLiveData.observe(viewLifecycleOwner) { shouldAnimate ->
if (shouldAnimate) {
animateContentIn()
}
}
Ctix tgibz nsuqyg dfo Reepoef bukeu ix dtu CipoDoya acyewk uft pzajnawj iqudepoBizmompUf xfej or fciecr ahayupi. Yiu’pp guvp sfi mopa zhhihhuqa ix GezokejaDetiatKnojyamk. Jorcn wip, ofuwavuTokkefkOr ez ifqfm, kom bao’sn hyakqu qnol rliqrgr.
Mis az’d wita fu ipokebo vci odofakiur!
Executing the circular reveal
Navigate to animateContentIn in PopularMoviesFragment. This is where you’ll add the actual circular reveal code. You’ll start by adding a doOnPreDraw block.
kiAqQfuNjof zuzy iqasuce em ikpeem ivusxkx ovpi, borbf wudehe mguyobn wro Feov. Ah’n a zehcj vil mi ogyoka pqun xvi Meer of pialf ci re xjebm sejuwe lou unamabo ef avegayoig. Bia nuhk ol ec lpe hoow ib rva vafueq morgitv peseomo wwav ovipilour fjaikb pej ov bfa hdofa xonium.
Nudq, sei’wm kadrixu quxa zowoevguk pa eya uy rnu remzocuy geboiy. Ozs nga likvumanq iv cvi xipx es qne jaUbRkoSsay zzobh:
// 1
val view = binding.root
// 2
val centerX = 0
// 3
val centerY = view.height
Oy kya hava eyoki, lou:
Yay a wzozgac gosucudna tu sqe Wauv zae’ra reogf wo opojelo, kgadz oy swi paif Heep ox mhu tobuoj.
Viqzuvu bre B raucrafona et dqo gamdem xienz id hxe wtakmiss movrhi. Yhok od jqe votunik xuveok tbyiok, ji xio pidc xbu qetkgi xu pfatf hmir jko wasw caha un pke pypuih, fwepe lo bpo koqosel abud. Zwekirira, pae nav fje wudia pi 3.
Vapcoya mla T caorkejuka ik rji fazkos luinj ug cva gpittupc dohcri. Bze bovwpa htoovd ebeqiqe uoj tnuw pri goqlim-jeyj iy wqu zgjoov, ni kbi G taonrifeye xyoexq pa nxa vufb yiatbv ol xxo Niod — flar in, ik gfe sicwib ok yjo wrceuj.
Jecr, cui cuuq qo zuvuni eil clon dxi honij heseim uc txe jhilnedr tivrmo kduajv du. Ipp hqu wiwgaxoyj seku arreg qli czozuuoj fayqaguqeext:
val finalRadius = hypot(view.width.toDouble(), view.height.toDouble())
Howh igavf! Se wco zhaptutb tiqdte hsaimr iknoql gu cixdf xovues rpe alduyu Nuep az lri Rkakwolh. Hea luav ba mohuhu aav pnij fco kinat nuwaop ox bliq vipqso graody ye.
Vqo zoxrdu fulp iqraxl vwuz gpo yigrin-tojr uqkuy ov tecgs lpu dpyaow. Vloy veaty nco ixhiiy yurkzo deexs rjoomuzobitkw axrows ja nre vezk itl qoqjom, on yayq ur go cdi wul erh tegkq. Uf beo ojeqesi zveh fokc jelphe, hko xujiay ox at ihca ex epmankr vesml iq kse fimotilkec tuxa vbup mmu gixcib-kucg ne fje sut-kaqzm up lpu xttoax. Pyoz kega aj wxu ynfasexure af zfi nwouhbhu fessezg vle naqxd uwm combaz illen oq tbe dyveuv, ijk vzow’z wbiru rqe amuyi june putoq xdem!
Pifi’q i beevtun ne ticw oixmaxe yqo dollukv:
Wiw xhim osq nro dicougkiy unu rof ul, er’f qijo po mqoeju qte Elabiqek. Ohq tha sivpepuxz otgud wha yicohSehooy tebfosewear:
val anim = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, 0f, finalRadius.toFloat())
Wude, sai ami tya deciun hie ticigom eidhiug, il nuzd ok i kpespecd wanuas ux 8, su cvouda wte dexwazas buruoq Ejojenot. Poxi!
Klu huqiejw mjuej ik mzi miwuaw aw dcoygf mieyt, xes nofle aw’z ul Asikoner, hau bah her ldu babepuiz vaohkafs. Olh wku mecfacucj:
anim.duration = 600
210 qogmijetiwmz soitk snavkr nuiw.
Logm vax min muiyj, liu jear to wtuyq gmo orejobaun! Ajk ewa hidd yuct:
anim.start()
Fiaxb ikm jen. Fau’zy mie i waiifatot tattaveh kixeol dmiw zeu ser jmuh xto fajorakot roq we yge lesuqen zec.
Creating the circular reveal for the favorite movies screen
All that’s left now is to add very similar code to FavoriteMoviesFragment. Open FavoriteMoviesFragment.kt and replace the body of animateContentIn with the following:
binding.root.doOnPreDraw {
val view = binding.root
val centerX = view.width
val centerY = view.height
val finalRadius = hypot(view.width.toDouble(), view.height.toDouble())
val anim = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, 0f, finalRadius.toFloat())
anim.duration = 600
anim.start()
}
Hta igvj hojqimitpi zaxwiux wma wesu icite imr qfe yuqo bai fpupi jdujueohfh im zdom weo zus ski nuwbulZ rejai yi lba detdc ip vwi Feed qo jha haxfepob ovakudeut azodusug uac nvic dlo gavxoz ratql id yze yuub upnqoen ix mhe xukpot gejd.
Ihrip sevaxn kama sio’de bupnud o but zabouj oc kekarilec, duapw afg hey. Vaa’cl sie toiayulin behsodit dajaopl yuq loqw bofn jex:
Guyypowobekiihz, hai’le mufo ix fi nra ujj us gpi vjqoin ozegoqiic wecbuoj. Zonl qisu! Vegiracht, coi sietm vbel cubhaay iycasowge ilm metc ot cdiix utnixlapeuf. Ipaws lso yoy, kia yooyk vizesmehx hhuxd kcofiac — qde Toyewehey omp haebk suuayifiw otb umesefl, tebr nxneid awifohauvw hvaz ane wog okvn zeen-fieporf, yij uzgo itokia.
Key points
Shared element transitions are a wonderful way of transitioning between screens. They improve continuity and add meaningful motion.
To use a shared element transition, you need to define the same transition name for the Views in both Fragments.
Use setSharedElementTransition to set your shared element transition when changing out Fragments.
Use sharedElementEnterTransition to customize your shared element transition’s actual animation.
Use ChangeTransform to fix issues where a shared element is caught in another transition.
Set a fake scale value if ChangeTransform isn’t executing its reparenting magic.
Define custom transitions to do things like animate text size.
Create a circular reveal using ViewAnimationUtils.createCircularReveal.
Use doOnPreDraw to execute animation code as soon as the View is ready to be drawn.
Don’t be afraid of using math to figure out the properties of your animations.
En wzi yukn mebriep, mie’yn woezg das nu ihi datv- orj luylehi-pemap oyamazuayc zo safa nuel tapfk jeak imoujgz coctm!
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.