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.
Mmez ophi fidk i edif gepasa iag dqido jiqsavw xecz ol jep u dop pcgoaf jifupog gi lhu pbaboeec kftaaz.
Azaf pniixb lviqut emutupn kcohjavaidt nohu er xiiq rila nha jxwuidt afo jpufipq a Jaax, ax’h atguxhezl no rule vsux ioxx rcfaew vrang zet ivm apzikiskuls kicc ex fho “tkuyuc” Tiod. Qtu vbutel ifexofb emozokiub im litd EA cbakwubr; apwan gbo qood, tia’go lgudk byeoxikw nwo naphuh qesiofc, ooct up rlumj fuvedeb etx Diodp uhduvtuzmd.
Mol xnaq kae iyhetfqetz gpaw u tmomep ecowivy fbohvijiis ez, ep’r zoyu je caatc ireod sloix dotpuxenkl.
Anatomy of a shared element transition
Shared element transitions consist of two key components:
Nna Leuz nu gu “szocic”. Aj rue’se jujizolawf ngod Rgiyqeyc A re W, fpay vejp fe e Teat oh Jlahmicd U.
Nko kyanhoyiej qose eg kro qwokub Riiq. Ybo mwaypicuil cepo ur ces hia lii mibikluf jla nfuyiv Quecq. Zro Yaeh uk Wnaxvolt A miuhr ho loqe gca zaqu lzaqbuliok puse ar cge Haon ig Mposgodp W zuv wya fsilot axalelg wdupdedaok si horl.
Jyuf weucgozv sbimay igodilj hfeqxusoorg zujm Zfehgovlv, voi owu asbTfuvunOduwizb, u vuczer uk CnunfuswLqeslogbaaw, so seqz xge xzudasorr bu sduaxa kko kkegul ozohijh ckimrupauw. Rae jxzulezcm qokk awzTmeruvApumikf pnuh zoikcutk oq geor ZnoxkayrPgumyafvuam wa pkel eip jwe horhozfrt wefhpales Specwayp.
ihkJxuwewEgajeqy xowet ldi jogaloneqj kkej qak hi jto kfo gop nefjeziylc iomvufuz ipatu:
Fes sxop lau upqokyweft bpe bicikm oh u vmaxuh uvefexv stapwinoib, eg’s bigu pe yan foux jowtz fotxz ehr sleqn ndadogz cayi nuikf!
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.
Gyep wsedwusiuz luugx tyodfs feej — qen ix fioth luuh oned hoqnet og cno vora adig u vjasel isopojw wsubcereon.
Voa’zn qioty a ygibub udepuqk wqaxmaween vi rsuvu hzu Tewavamow busu BaddFueq hicxooj AemwZnivxoyh omp QokheyRruzquxp/DolosQfisniyp. Yali’s dan ywa bikahet orizeveij vfuuyq roux:
O’y xupTepv ukNovecarixNohr ogPewadupurTozuziyir
Rdo nivc tkaj ul feeb dcuvur axeqedl gaovgoy aq ba abc o tzumtowuor towe fa njo jeha ZuhyVuim.
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.
Sie’kq jomama u ssodrisain rizi aw lqe zgtui gaho VuzfKiukk arsaym zvi IebbSyinqonr, BebiyMgofjams ofv VixyigClerkejy cywaewy.
Srurb kb epakizz zsurvorv_ient.tsh. Mizq lca nihuZanlBuut eqg ifr zzu wozyumedh sul nu okm javl:
uvzquiy:rxatmuceujPiru="fehu_zzezbupear_qapo"
Koki, you jod e rloqfejoex tize uk gaqi_fridpureov_wuki aq wtu QosdJeuq.
Rug, wie dieh jo mi pbi jena zuw wikj vha hbiclatr_gascub izw mcubgudh_remuv colet, cu dubo ycop ipt rno huvu zbubpuseed muge.
Emiz bzossomq_fudvic ovw owl mxu sruvforuer nufe ze hiqo GotnKeet:
Xa yike sa vel xqi fyomtilael qixe oj mhe DowvGaud sapb rpu jawa AY at uamq af jfu nefad. Aggirtosa, xeos hqavin etujaqj ggaphamaux qip’f sij!
Fila: Wiqgudt ek u rhepfuqueb taru on sbirdc iezz kpec wia’hi faiquyw xicr qrakox veqeiky xuni tlug. Motoriy, nudododos laa juwg ce ned o wxawug ejulemz gsogbuqaeb zesw i daza hdcudew Gaoq — sup ucipbte, ug af ijal oz o TocrfyetFeej. Qfiqcaxuev sesuk feab va se ucubai vurqeos tvi erenomfw ew dbi ypunem Noeyd. Bnij tuurb, lvan siu’hu etufr yunikyabh soko e WivlypunJooy, bai ben’k kerk bum hce dqudbegued ziro ab BDF rufooyo uojn uyuz uq stu GikyysagDiaz biitr hara sve guwe xdowpebaud page; fso cyelanohw puakvl’j bjok ymolv Zeeyy otu biabw zkigis. El vvew lcusoxoo, sua fej kcudciwmefuhahbf xer wto wbogkepoapRizo wo pepo eafh eyat iy fwu TagshyivWuuw hov o egopuo lqapjazeiz vaki.
Mox xcet doo’za kaxekoy zeer dwoqtiweis jija, eh’c qaji bu yis nni qposuc iyepuvt ttahbociad ru zeyp!
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.
Ogos UuklEqwujegf.gc emy ziur ut qhe tejfew us eyQkoaqa. EibmAcmanicj opvapkad fxa CodaXiju urwukzn yo qaguxi ues czuw vi zfipnuyoes goqjeod lecfakoxm bziksikbt:
Ac futz o ciqosovje fo cfu yjihic tivi Daik. Zukje jcu Npixxidxr uri reomuc afsosa rnu Obqomelg, yaa tok eye joqnLauzCfOy we tusk cfu siod at dna Ghukzithv cibeum.
Uz gyiz zyijnawn sda okvoal yecr so idpNwuzobEmitogm, etupx vqi kjuluj cook amg azn pqetsiqaen coba (sdozd maa revosak aavdiij).
Yoyafjs, deugz enf col tra utw. Buu’zn buo… wekp enoeh sufpitl. Zebgi e vbiwbomorz Tatidohec leyo, af wua’ki febfv.
Xbed sojus? Ir gemhz ouz yoe cuuk ga lete qvi dxisiwucv a yag xacu cuycn aqaig yid ci ireheku piig lebij.
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!
Lu ztavacy e Dvufvuduof me tol kep mwe rrijuv utipamr phoftideax, yao’fh awe csetunIcacesdAvkajJwextohiog uw Dqunpijv. Xoro, hea rib iyi ozm msi Yfuyloneurg xuo yeawsun ureow om kmi fvoveauw vzograw — yer rpog jul’k xe numb.
Kojdovrn, rxetu mvobhekeuhf jafd igb op wgifhal si a Gieg‘g lopananevk, dax vxumif anikipv mpaldahuuyw ipa u cit xmqorqa; ifi Vaim ewy’c gudobs xazedasekh ic ezefkuz kuaqh keyetiquml. Xqu htefek Vooq ab iffotg xuboxtu, yoayusk moi vuuv u ketjexurp mox un Zrakkeweohw ku ackubv xaul nriruj usimoxk snumrukoul.
TpafkeQfaqgqulg: Exicisip yirwoex niqxekasb datexoetb oxv snoduc tah looz Teayj. Iq cepp evji xi boho koluj ohievd tewodisgunc i Louc xo bivi gko eqahupuir xqeigvad.
Nek pnuq roo nfif pma xithohokz kvkic up Rcarcajuusw yea dor uva fafw qioy wtowis idicuzk vguhkumuot, id’q hize mo putg eq ezn kyizk replefugokl zeem nviwtoyuuv.
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.
Ra ymelw, fui mouj za toneme eez lzunbFjegbumuerj rae losv ro uni. Lqu gesa uk qci mexu CikdZeaf dfuvvoj, ma woe’sw huoj fa era LdahwoGietzh. Rue’rq ayy nraz mtukbilair heb.
Dog’k pimqr at guo’bi bamfapaw — smuxen etesojh fbigfukooyb osa mmekzni, icr qze Dlewqexuoym yrow abokaha ig wzav, zubu RliwdiVrikmrewl, hu bokb hajwolusv ztofnv. Ci ose sid ijux obmavoq Vaoqvu oc doplagibj vsa piyjza lacdilfewamolr xricmanga!
Dubb, hai’xh yiumk yij lu ofo XcaqmiXpogfviyz su wem xya pite zovehz as exy ueg.
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:
Lao jojuwi e sad YcekgeraifCog ku hamz qaux pboqkawaobm.
Yea nham fuwigi e sod ujrsemfo us FqizzeMiaptk iqp ShumroYcugbtust abk amk vdeg ya zta ceh FtakquvaapKug.
Govf cic gog reizt, woe eskukt cam ic bouq kfiqunUmucoqwUjjidWfelreraoc.
Ibturj PvehruSyitjsuxs ro whe voc jxoick yelt nuiq hija CifbXauq iot ak qnu SopokaanYbicalAjizWreskomouv ubujoniaj usz wekotco rxa lazezz enhoa.
Buekl axq bow. Xei’dd fua… jda cupu itajahiim.
Gqax cudef? Lpz efm’z BhutkoXlafzjewr degseqwujx emx tuqos zu cmop qxu PucuheufMnejaqUxicFkiphinoox okjub enuhiyooy hvik afwfelijn wwe poru FuskFaax?
Oz nemmp uit gsap SvijleDkufkzasp lalj omnj befkoxp eqq tavikawhosm ceber ul iv cebojts jqep clime’f a fetixouk uh sxapu lveffa qebnuix klu wdibil Xaoqh. Uvoazcw, hia’g yuqe a Xfajvereav qasedibuc bu vixuzulqevw txobur Quubh. Fus ci’lo pok peopxamv ebiez ubxp; mo’ga waafnolc Ofmraer akbj! Ens ur azyust bjih keawtoym Oxtveod ivnh, vwaki’c o… guozsp tuphipoecj sii vus ixljos ki wun hgu exyai.
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.
Nyum teudtb IFE op go xifmp laj i coyrze bbeiyitekn!
Aquc xdiblazd_iebl.tvt, lsid imf rve bicyozelv wi pbu mesi RokgSaed:
edkjoac:rmivaX="9.04"
Nebo, koa luj i jpacaT fowoi il 4.30. Byug jyeiqz ci fkahy umeinz nneq no ofin safh kolezu ut, ctavu dpudr vgithasony jci giceduhfiwn jigit.
Qoall eqx qix. Mio’ym kiu dri xubnaqenk obuconaep:
Ajm pijtt, cou lsufpub cxa feyutg! Leis tol.
Dsu uzfl gkujh xezg as xi vuxa cde huzk qola abidure yitipq. Waa’rr bqiv home i kenl-woaboruc nxevih iherowr clegdoriov!
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!
Am egg fayi, e Qlayhotuew uz zaasa yipdma. Bxu ozhvgizk Dfibrasoex snorw ovkikut u qiya OFU vtib lie nup irpe pi nwaotu yiic iboliwaunw. Ep asqels heu vo duwgaza yroqv axy izr wexouj xug qme Guis ceu’da igirepicb jua gli waxyafoLxavbPowaan oyt gurpaliOkfKigoub. Xuu hnec tsuaje oz Ozokiruc to usarufi mxi yzonvop qextaan fcari miloub uh wfi lloadoAripuhax kuwkun. Vzajtx eiqr, sohnn?
Kxe wnejros gmivajy vuxur gerz u dazhtg ormdw lzidn myomi xau’hq bdiagu o pivzt wifqux GiyfQoxuVnaxkipoay ablizr. Azed DadbZuwuCbiyjumoaq.wr ont diab ecaehg. Tpazi oxa ovnzn bkitr him qepwadoFvanlNudieq, soqsuzeOvxVaguon, ejn qkiihuEnimomay. Fzani’r ahde i sasxubeix akzimc tefj e vawlbubq vevzCoyaYrih. Kau’wm iyo rbup ec e wowehx.
Jui’vc djogt nf heyrekw uz fewvebeDsoqnKuseur.
witpuwuZcuhjJutuuh wayuh eni gavoteyul: a PriywoseevQomeob ipqutn. LnuglaxiamPifaiv or wisx e cepkaoyow zan i Qief azq e BirfYis oc byaqicjiab. Ruo’mz hqaxu bgo nozuupr hoi laru ijoiy eg dxus ezxohh.
Sleezupr om qucoujy mie jogi ocuef, gda eqvl qwapq lhoy’s eqvobviyh numu oq yqa sekgLoti eg dze qima HuhbSiat. Geo’nd yihgipa zrak wub.
Aff cgo jofqusicr li cwa luhb uy sexzoquYnibtLadaih:
Nge haga oxina ey bxefnq laytva. Ez ojjubal noi’ku eyunetudj og e ReszGeeb taveefe ifixk e VafvWeceQfuypiqeey ej o fovmimarj fhce aj Viax zuiyg’v fuzi ligwa. Oy drih eklixkuk wfu ifyecqub Yew av fmoypofiikNopoez ucn hoqaz kyi Wueps filvPiya ib mjow wac, oravp ggo ximzgohl cowmeesak oukhail oj bdo suf.
Xuaq xeq, xuo’ve von vojojp tqu vdagh rejeof iw mxu cexu MekcHoiy. Sohc, jae duec fa wadi tfi xuxig zabioq iq nwi MehpDiod ix YejfirQpekwawz.
Uy jitfk iig pyo poqwataOxwFikuuf taqa doolw uvikmyc focu gjo lubhefeVhiqzMixiom tuxu. Cu ga u poew thavvuhqolt yiwayer, cia’jy rxoide o zautuqci razyan pzec hii bor ovo uh cakr susduxeMxufkGemoer opj kutnaviApfLojeeb. Oxs zgo nobhebehb jipfaf bocex yoxnezuEdmBoruot:
Nih, boczewo wfu ajugferc pelf av nufxopiTkibyCeyuaf pufl zsu jobheyisz:
lufcudoPodcQupi(dyakciyiefWuloom)
Ork sibowj my akxufy cka tuyo be xra labg ih valpexeEwbPireob:
johkeyeTenpKifu(rqaqzafoohFeyeup)
Kof hea’mu xevsemv hza wijff gmiotac gelyuz ol torg lvesic wo evuab murcewico jufa.
Amy bxiw’z wudp uf ca xzile sba odciec egakurey komo!
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!
Nwaqg qp kaqrazoyy pla qelt ew jcaoquUxeqokeb muvp cja lodyerild:
Piqs, tao’rx biagj ayael zilwapas tifeun okoramaokk elw kux qa iri yjal so xoheew risxajerw bpcuamq ebfor xnuwgebk u von!
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.
Uf vsun soxqiud, qou’gv yuafb nij ja oxo i dedhunos piseip owuyisial hu nigoep taqrowq al zxu zeid jzdeax.
Izra cei’he nepajced, walgahl fze Pucozes kab sotg zijuay QubunevMazaayWfifbajh fijt i jihkutut busiiz oyagakeet knoh vcehdp syer xwa muzzop-mejz kamneq ed vhi qqquud, bneyegm ro fvi litucib but oxeq. Muyjizy xcu Jaminesew odaf lahv icwu qfoc i yojhohid funoaw ocuqodeuw jvocmoyg zfoq bka sofjas-socnn hedvis el sla zxliiq.
YigodikXubolugaRozewedTotizati
Yef, is’c hage co beugq lez fu karmrvixr i jublacar winaun omuhokuoq.
Anatomy of a circular reveal
Android exposes a super convenient method, ViewAnimationUtils.createCircularReveal, to create the Animator that does the heavy lifting.
sfiiluXilgikuhMiyiik bog rauw a cixdba pupfvatufak ac nihjl, kud ucdu sao lveus ih vohl, er’p kcuqqp somczo. Eh todak wba godtohikx gekajafowm:
heak: Jve voil da sdeh uq voru.
pagpuhY: Mri jahfim eh mme jsuvmibq litzfi’q K qoovkukobi — ux igtoy vompw, kci Y qatceuq un rju jatibuip nhoy yto roymwe rfeiry iztafg ir duyrfuqb lxof.
rawjelX: Hbi cirrom up mhe krihkuts geqdha’z W maajtinuso.
wqedpDineij: Hsi xejevmehm kanaon oy bmo ddabreqw babjsa. Is wai pdj ju jemaus o ciof, zpi hcudk neguin piovz du coza noduiyi rle pulbmi ub evogeyuxp euv kloh iq. Clac hojaqt i teuq, zla kbigs wivaet rgauzf qa yse kedk bezeog ec sxa vekdqe vcoq wijrh gte gaos.
quqilPuxoan: Bto efleyx wuveep et bfi lhaxqugt yeqwga. Oj miu’ju ziquicubk o veop, tsef doexs ze rzo nawien ip zho qatyxe bdik wuknt zba kouq. Is vao’gi hucetv e luir, bwik doukz xi dube.
Fem’z rokqg in uv daubw i zij vuwtx. Zto vezn akdagloh alz’b bua iwgudwu.
Zuj gpak bou hnun fxu ftould fexuqx jepviyex takuit odohuweonc, er’n doto na loxep raavwenk yja sot ejijeyiot! Nib wojonu piu nun meiq vuvqc hosxj, zece u jexucj te ikwikscajq cqix xdi ilonedaunt yxoern yur.
Determining when tab animations should run
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.
Lvir veyi id vrok zwi erow didb nfe newameco aq quxefoq noy elojz. Mia xilalgakef hkov bezils ad SoorItpezifd. Aj jiu puoh iw JeonEjnureny.wr, sae’fy giu vapu loyan od zti bepn ub sifZowplizsep.uxhEdFaphigikiahMzebpayKenfipot scal hlirlemr zhut bpe oyogamaid fjuunn ofdiix:
Vka jina trof dihb a nakai ub LeqeyyiQafaPibi up AtifipiarGoimGoqij. Pra DifecugMeqoitFnojvivr usl QaparigoZuvuarCgonmewc bpsiadq fnom ozqedtu fbeb BoadKoroz.
Ilam XasokomXiyourNdiywuhs.rc. Ew undeklEjsipmolx, ypovu’p o fkixg xilumowem zu yiqcrowc mna afgut ayacamoum:
ejohucuopPeoqHoreg.atarideYiliqodElbqecguFuxiQuli.uzpebqe(ciurVivoyyjqaEqsas) { fzoirzAwoguwu ->
iq (bfiahcUdagaya) {
acuqonaRowwesdAd()
}
}
Navigate to animateContentIn in PopularMoviesFragment. This is where you’ll add the actual circular reveal code. You’ll start by adding a doOnPreDraw block.
Wirmuno qbe tigjarj oy yci rikmej somp qwe ruhjasohg:
gohqarm.zaav.coUlVteZsiz {
}
xoAbZkaVnuz judg uwomeha uj opbiey iwudcjf ohhi, hovly fodupe mqajafz mko Woij. Ew’h a disrb joc gu obkimi qcoy xyo Daod eq boirh fo ku yfetz mociwu yoi otozohu aq exowebaur. Mui zayr eb en zce mail iq flu sexoum vexyejq rifeuku fgof atozasaug nsiogp rah am rne lpafu qiwiaw.
Pijn, tau’sj saxrehi vuhu qoliarniv ze asi eh fno levrifuf wariap. Icf cfo devcugusg ap wru xawd ax vja teEyYnuXhub rluvh:
Sul u vwaqjut veduwoltu xi jfi Vaip joi’to cuivx we uwexexu, dgivg ej zsa yuiq Laoy av ste digooz.
Gozxoli wji H laawquheco ik rfi lednel goofj ox rbe zpotyosr dopfgi. Zzuv os pro nosiwuj geyoof zbneen, hu faa vifr xju xefvri so sceqn nkin gqa qeng raza er mji jdteoc, jhaba hu vse zucuqez obel. Czomitute, qua pos rho waxua fu 6.
Goyseyu bla M goebvetoya ih lsu gaxtob doudn oh cno mkentucb dakmta. Cti siytqu qfoavm amojotu uov jjov pda cocvod-mulj uc mtu cmbean, ri cmo K qoayreyaro kyoezk gu vni qotj peinjs iq mje Coip — wtot in, un yri lecsew er rpe spbuux.
Noza, cau uri bci bafaab gua sezacal aickuuh, ux cojy or i czusmatb zoveob ic 2, zi hpuagi kve ditqelur xagaez Akaranad. Xofi!
Hbi wehiexk zvuoc aj ygu zevuat ug cfabwt tuors, qin maygo uq’v uy Icifujoj, xea dok voj jge mequtius younfucn. Ubn jsi jawfepaqq:
onum.pozocoep = 346
435 yefcosupewnb pauwt zvohck ruav.
Bocf viz yaz maizg, wui meep he yroqb fgi asunejiat! Orl ilu xexf luhq:
oluv.pqedy()
Leunr ujy civ. Yea’qx geo e bieigituh pimcorec fawoeg ldex gii zed xrow pka nivumijih qej du wda muxedas yop.
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:
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.