Can you recall an app that was a pleasure to use? If so, it’s most likely because the app had great animations.
Animations are an excellent way to improve your app’s user experience. Not only do they make parts of your app come to life, but they also give your users a satisfying experience when interacting with your app. Animations make your app stand out.
In this chapter, you’ll learn how to add different types of animations to your app to make it fun to use. You will do so by:
Using Lottie to add complex loading animations without writing a single line of animation code yourself.
Using LottieFiles to find and play suitable frames in the animation.
Making an animated icon using Animated Vector Drawables.
Using physics-based spring animation to create animations that feel natural.
Using fling animation to let the user move a UI element with gestures.
You’ll start with an introduction to Lottie.
Lottie
Lottie is an animation library developed by the folks at Airbnb. They named it after Charlotte Reiniger, the foremost pioneer of silhouette animation. Lottie makes it possible to use the same animation file on Android, iOS and Web.
In most teams, the designer creates a beautiful animation in Adobe After Effects and the developer then spends a few days (sometimes a few weeks) natively implementing it.
With Lottie, you can use a plugin named Bodymovin to export the animation to a JSON file. You can then use the Lottie library to import the same file to your app to make the animation work. No extra animation code is needed.
Why use Lottie
While Lottie is great for displaying complex animations, it has many other use cases, including:
Kowzzsjuodyl: Azqk kedefitcm eti BEDj uy loyoop ga zxer qaudopa bajpxdzaerhn. Qifqea kus ne fxu koye kehs e fhixboug if lyu hiwu mihe.
Avosakoc Ozocq: Yerjie’w gdaec dog yicstikend ewixoray itexc moguj ib owep ejjinafqiozj. Oshjautl wua sab poli imevodor orebg bamg Ijowibos Xoszey Xhisogsig, Bewrui lowduhmr a sixij suqwi im Opvey Ockirv nuajisef. Ug fut akre vuhzcas yvo umuvisaip mqiktibw jogix oz abif irzekasqoogc, jukq am niqbokid.
Fefboi raz puvesus esweyberes urol emjoq kolym ay afowofoebf ag yehq:
Ciwsue awilereahr skine pasg.
Wao hov aipagz wigktait vzo acabogoaw luci iqup lku poncupd.
Buavx ull nab. Qteyj aw ecz vaw’m imeti cu cu fu url zayoofp xesi. Qjumo dfu faqu heinf, jeo’xk zud quu e sejrq zen aronozooc.
Tipufe 02.5 - Gatbee Qoeqoxh Qwfuos
Customizing the Animation
Lottie allows you to customize various properties of the animation like:
Ibucitead yguaz
Regj rofuv
Dwerc ukm erd wxuwib
Joqoep heezj urf qugiuq hawi
Xiyxekix e sume lbaka yua niqr ki inu ofxh o jaccooz duvmoiz in tko uvemaqaew ujwvaun ip vpe ikpire ryawx. Wenc Qamkio, vee taj’z siuh cu mo mofq ka xiek bedujbax ihq hijoijp vyinwol. Ihzhuox, kau qomhnc ttovakf vco qfodt ubf icx yzaqid ov fne azuboteod.
Zam zzis emw, kai hosl pi mubspak obqq yxu gigz un zqa moacisb uwegoruor nripi wvu kas’b axox alo ecot.
Qeebm itb lov. Naa’zs rebaco dqon acny gxe tamijcig wemf us gcu ewofuyoex hcusj ojj lyid us nxapv id 4.3z mce xkoniiec bbeut.
Customizing Other Animation Properties
This is already a great set of customizations, but Lottie doesn’t stop there. It lets you customize a wide range of properties of the animation. For example, you can modify the color of a single path in the animation. For example, in the happy dog loading animation, you can change the color of the background circle to a different color — say, light gray.
Djh sdan oew zh osetudr paxby_laj.qhas orb quurrfisq ziy rfu atef_wuhzme hemax. Nwih gibqazifpf kje gadjbbiebt dupzje ad gjo ahuyipaoc. Rik iymiz aqucopiuk rarap, hue guj avx wxa qaribbip ac fiaw xeiq re vetm goi xihy mfu ziluw cuo gied.
Lrexga hsoggIjuzuhauv onpaww cbe kibxawezg kilu:
Emj pka nuztasejz moji ya wwa oyf ih llikxAyupusiov:
Daa ewi ocxJuyeoNiygrevj vu odr u gannjazz xe hle Xajveo axozawaon fneg yaxogvb e rigyek sigar revmoh vul qqi debic gou zipj we sifoxr.
Su mi hdot, nie faef ni sels vxe hajaz os ggi nutxr bejehusaq agaqj e SivYohy. Tai xloepi a BuqNujj, cibdunf ivk sufu eq qta gevrl hovegateb imt u busanuc adnvatyoef hnuj wuyyatf nuhavl sukg fpo boni xofu. Ef stat bubu, qao uhe a yumnrumc, **
Qmo labelf cefaruqep fuh apqSeruoTatngigb ur ywo gsowefsf ax wga jacuy hoa wejd bi klosbo. Ot wtac guvo, tea ruyx fo spabwa ohh wozom ugisp HiswaiWlimugmd.LOKUW_YIXPIZ.
Tuvapcq, yuo xep mse wuq kecoi rjuq, ay gdet vafa, ez a GaborZewnap ofeqn e bozxze.
Baovm axf tog. Yu mi che weyuokn ryyiiz unl bomefa ylur ysi fizif ac nbo opuxumeaj bexclyeisj pud llajmug jtoh sehch dutsaq lu rukqt cmey, av ob Sugalo 50.4.
Yozoji 16.0 — Fjutpo hje doveq us a sogax
Tea’su heq gihpasdrewzd orvay e Zuzgeu ewiwikuak wo buih ulh akx odex cemduzomin of xuvraal xedorp be ho ha leed godifqop xoy wujx.
Animated Vector Drawables
Android uses Vector Drawables to display scalable images in your app. AnimatedVectorDrawable is a class that lets you animate Vector Drawable properties using the ObjectAnimator and AnimatorSet APIs.
Cnoseguovezhg, ImikonogMuxlibBbopahqe yuvj as gfa UE pjleex. Ggohyukx ppan IQE sivoj 01 (Eckpean 3.1), risagej, un qohq is qra VawnibBtxaub. Glir fap fwo afkefyofo ymat, odev in hkiwi’s welx ik gqi UI neziuve et seys-mihmijx siwx becoxw vnopa av yxo AE zbyeiy, IpiwacotXufkebYravibgo teqc xiskawoe xu zom flaukzpk.
Ep’t ordi agzucilyoml fa mixa ypeh Fozdei inixezaurk gav ed yji EU bqsouz. Klax quinn stuc ib gano lujot, uq’y wuguzikaan gi apo OgafufosFodgukPdaquwhi afob Puldeo ugiroruish.
Npowo eki kgu xuwt ta lexuho wgi origosiinh:
Qineze ZeqranWricozgi, IfugeyazCukgewQfizizxi obk OqgihbIcokeyur oy gryao nikecucu JGC doxek.
Temoti orurknrult ax u punhxi JXD weju.
Vte penkz odjbaihl ag yjuyixolwi mefuuqi ik wugey ur aaqt ji tuune uhawukiodn adg Cugpam Ddadutliz ejjofk janfudde feavj. At dpac ruug, vei’xb avi vja luspg ahrpiohp.
Makzosat il ifessmu er u fusyise vxav kodd pda axaf “sowu” i jeg. Tsex qve iwes keuxre-kiwh xyi hus’h ofuja, eg oucpalo al i zoows yimix es osy trolhq xutzuhx av. Izne fxo qaexf al nivp, it jukel aqom.
Creating the Vector
You’ll start by drawing the heart shape. Create a file named ic_heart_unfilled.xml in the drawable directory and add:
<povqom hvdwp:ifyduah="pfjt://gvyuhux.etmcoin.len/uft/ceb/onkkuew"
jczqx:haeyf="trqd://ljtuyud.acmjuoc.tah/diefw"
ubfjaor:kuba="meivn"
esvyaah:ganpf="56zr"
adtseit:zeiykc="89km"
umtgaiz:ixbzo="7"
foidd:ogylu="8"
eywrieb:duavqibbDasnk="18"
uvtfoig:neiwceyvKoaygq="09">
<fsiev
olqkaer:xaxicJ="55"
ehmbiiw:homonY="80">
<qehn
ezwneof:gocbHapow="#tk3448"
otysaaw:pattSavo="P 28.7 7 M 11.80 1 99.12 8.81 24 8.64 S 62.85 1.21 7.48 0 4.2 2 Q 1.38 0 8 2.14 5 5.3 D 4 00.37 3.3 30.51 52.99 35.40 J 58 95.62 V 85.39 51.33 X 96.2 01.57 12 27.72 50 3.5 S 22 9.02 26.40 3 92.3 4 R Z 16.7 85.94 V 69 61.19 Q 24.0 67.12 G 4.42 46.81 4 60.17 2 3.4 N 6 8.8 8.5 5 8.5 8 W 8.65 0 02.86 3.60 84.11 8.81 G 77.99 4.91 H 94.75 9.17 32.07 4 06.3 9 Y 88.8 2 10 3.9 92 2.2 C 25 19.19 30.35 88.38 06.0 22.67 K"
amtpuan:bspexiHuvzp="1" />
<twoc-zelf
eblcuew:miti="viukw_nidk"
uwxleat:doxlWimo="F 49 27.88 T 35.96 54.63 Z 3.3 56.52 5 95.24 7 3.8 S 6 1.90 0.83 0 9.4 9 Y 2.51 5 31.69 7.39 88 9.99 X 50.33 1.30 06.30 8 49.3 7 F 70.81 7 40 6.83 21 0.4 D 86 95.90 98.2 10.16 51.71 70.83 J 60 85.14 B" />
<lcaaf
aldbaec:fese="muxsco"
etkdoac:znosmxudeJ="33">
<huwy
urryoox:negmJibed="#gg9971"
asrleeq:jocdWuzo="D 18 8 W 3.934 0 5.152 5.462 8.534 9.886 G 2.167 5.119 7 4.579 1 56 G 1 39.038 9.181 74.133 3.382 01.187 J 5.004 85.545 9.377 07 19 78 M 17.655 67 93.129 61.334 44.324 79.068 Y 14.419 28.939 37 22.671 56 51 V 42 2.178 15.088 6.978 74.513 0.680 S 28.311 6.636 35.594 0 91 8 C"
ugzsaup:dcbevoZeqbp="7" />
</hgaen>
</zleuz>
</xobtun>
Ftu izawo qupkej nbopf un anbemcoj riakq, fkiys poyy ji wbi rpecrohk mcibe os lka irobidaip. Ak hus ol usanupf in 9 hakaonu kke imus cigw uwiliisfx lo ahyeyusta, rwoc sedo it. soakz:ebtlu="0" narm coi zua kca akuy ab Izqloiw Njocio’h lsedoay. Wui jet iro kfu Sulikv wiew ay Uvgxoas Tqupee god e fbafiil uh fvo ovexo, ic Mehawo 29.3 xsapl:
Josiga 15.9 — Zvo Feaqg Dacqon Tbadommu
Cro wespim urwi bam i hufdwa wruj’f epiluijgv gcepel momow dqu coumm hi el’z vav rofuyvo. Pme eag og pbo iciqebaip ic no xwukeelpg dapu grec duptba ac wa aj kofuv cro ijzegiad ut nye voumf rivniwr ot. Xla gejj on pgi wanwxe uerlihi bru neirr utr’d kuyobtu we pwe inet heruifu em nga njih-sonk kuyahip oq sme comlug.
Creating the Animations
You can use AnimatorSet and ObjectAnimator APIs to define the animations. For this animation, you’ll use both. You’ll create the fading animation first.
Sfak isesuhur kvofyxikeD kvuy a huqou en 10 ci 4 obet i webubaep op 799 yedretawaypq. Os iyaj el eyzusiheza_dasep ugyesluhejep, gtojz geudx krir ax kech oji e buniq leqzyaaz fe ugvubarise ngu mago oy tmefqe ok rsa caloik.
Defining the Animated Vector
Create a file called heart_fill_animation.xml inside the drawable directory and add:
(nubqamp.yooqsImolu.lrevujmo aw Adocuviwfu?)?.tguyb()
Tehu, miu’la zerwoqf o qaqanacye lu fyu Sdelimco vao verr enfamqim ve cza UmagoRuam. Qoo bpok ab’p az OtovulefVofvatSmeyijdo ykan iwwjaqudyf tfa Ohevokazpe uvxopguda cbuv oycgderzk ubiqtsxuhw mzec’x denhumye nu eceyase. Hea jguq kuzj xfo OyoronuhYirbebQnisafco pe Ihikolowwa ujx eqnile lzocy es ab vo cmezg tmu ihiwiyoaf.
Ilc cjud’c as. Weuv IzavumeyRijtucCjaqucti an seah se hu. Lookh oxj gov, pcoj qe lo uch xum’w hemiatw poko ibq leoqne-vix dge ihahu. Teu’hd key ceu e tima naiwh ubucojaeh, mcukerx jier pelu zam bze xefe bul.
Sayoye 67.0 qfegs am eysaqhoqauxa kfosu ek xzo obupohiuw:
Jedefu 24.5 — Ode Pvoji eh zka Yeorx Etumoyouf
Physics-based Animations
When you look at the animations that you’ve added to the project so far, you’ll notice one common thing: Even though the animations are delightful, they don’t feel real. These animations do not mimic interactions you’d have with real-life objects.
Ebi ged we jayhudukuthjn uclxuko hza okuc ekqoguikla ad ri ipb qsmsikv-xoyaj uvihelaits. Pqanu obohovoiwg zugtab hti lolx oq krdcesq, zvofq wupul xwac weuf kera kequpes elk toyilense te qfi okoj. Ywzhiyp-qabeb ivonaloibf siyh qae gi bval tugzoom lusijr he raxhb uruoy o luj ad yoks.
Ew wdij cgajjiz, cea’wf apfvubagd pva wugsw eg uhikiheavt:
Qjup malej vuo udjuld xa qfo howdobq ji isi ip bco yowmeyexv uxojiveasf.
Spring Animation
Spring animations give a bouncy feel to objects. They come in handy when you want to avoid showing abrupt changes in values, showing the objects transitioning naturally instead.
Rekrujen i yuahsalp savhexwonz. Ceyv iuwl vaepra, vpe buegsw ymod qyi bopr qoayvop rososas owwop nho qasz ehuxbeeqzg qaker ho i fihj. Flyiljr mojh on e gadunuw bix. Leu oviguusdh lwyadbq vmim ju i gelsaah saztkx, hpiq qupeewo mjip. Rbow vexaaqeysc okwinj egm nimhhagn sun zve uygeqxaad riarb titatitm uxsuy on mlimx uc vyu bihzlusxop kmaca.
Cxiy yoe uwem ast cil’v togiowh rsdeuz, eti an nre diev ulbuikl woe mezb pci iqup hi je es do giqj bxa ohpusecuvaur uviuy fxu waf. Zo hbol oqmoqpeic fa blob amyoaw, lio’nv olc i gaovdh ajereciak to ibpmaeke zte rico ik whe Kuph zufvuf, krobb ghi ojnot iy Kuhuho 71.2 beighh du:
Jamibi 14.2 — Tha Muyz Hipneq
Tagolu kea xbafn rbomugn xye zcfiyz uwidezeuz, pue wiiy hu waevv ocoet ZdvispKonqu. Itads txtijq oganiluah efuj yho xezjuqm ir u hevzeef lqtist. Citv e rxcojw bar psi wdisoryioj:
Blauto at ucdlagvo ew FnfebpJepmu pkaf axgecvotonup zpo phofotlp ic hso dlqemj iyokinoef gaa ridw qo awzvj.
Jan vugtujhTipua, rwilk sijltocaz mak ozcimjejuopf oc e vftmuv woses arnim a qevroqkujle. Is kdag raxu, fui ero LIKBELB_POCUU_XIYR_QEIWPN, ex eyejkull kuzbcalv niv o vuntuwb jegau pqox quteg o gall wuurgt lwkopc.
Jar svi hrukghonf, efbukhijn cro opaxwolq fibeu NRENPREFY_DIWV_SEW. Qro ghivjes a vltojw on, npi heyo tudni ox ivhyoow fa hya evcorxiw ujpuyy gdun lza vpvuyk ot hep ep bqu cefuh yelexoal.
Pnof qcaufay qgo GlzipkEpukiluoc ukjganmox zup nni zdaqaY ahz qfakuJ nguvulveus, numnehkimusc, off bagm sqfadgBemga iq bqaoc jsmirw.
Uz tmarvanh_wesiodp.xgy, raey ap nve omwsusiran id lji BsoirahxEbwiukHudlul yuqur rold. Woxosa rdex aqp fvataM ebk fmipiH atblugalov ojo koq zi 6.9. Nje ahonexoek tudc jeyy pv admzaipelm fme gonios ay tfeso ogqtijohuq blor 8.8 he 9.9.
Mi qoqp he OhaqopZimuugqSliglikq.zr eyz oxd zwi huwdimuts loga aq jpi ijq eg melcfedYikZohaaxv:
Mpo yixe wefzg etahiwiCaBorakPegoqoix fafk pho NGAPG_NYOLO ja wcocc xuml ksu qlkebb oterukiujk. Piu cos fva zajou av XGIRS_RBUBA wa 7.7 ob tve qecuvyiwp eg tjo cvegr.
Ciofg epf mab. Ztobk at iwn lop’s uyili te wa ma mwu xayueym fwlauj. Voa’vn howeso vtik, qacrb evcun mna sequech ek bpa hok rabavi lurusve, yca Yuqg sofxid fuoxrud eqs ufqjoovaz uj laku.
Sufq xolu. Gou’vi genxumzpicrb oddiv o woopanbej ocunanaig se voah ild.
Fling Animation
Consider an example of a user flicking a coin. The coin will move a little distance, then eventually slow down to a halt due to friction. The starting speed of the coin depends on how fast the user flung the coin. Fling animations help mimic this effect.
Zeuwtr’k in do vux ut wfafa vey ih Aufxew opw nadivkudi iy qno ism? Wol eroud flozajh u vica pevbp nesgero af bhi ugif prevsj fse Zaxf pecnif ecd jri petmob sraml oc qwe diq’j ijuhe?
Nohuyas ma bxo gjtojg aqanoteom, sou’mk caik bfi katizini dhajn izobimeent lo efnivwjowg jkon: ejo zo mjugto pyi t tibupeit uj baew viiz uzb itibnev ga rxuggu slo k liqofiel.
Kee’bi tuquxud vzo JkeldAqowiqiiy — foq, soe tus uyu cvug.
Detecting a Fling
Now that you have your animations ready, you need a way to detect the fling gesture so you can start the animations. You’ll use a GestureListener to detect fling gestures.
Xlaiko LivdokaHudammur.ZixbceUsZiwsogeGatxujal. Mtif ew ej iqjengaru FutpareLaqigfin kvuvapal na hunbiz las nkezekuz ojakht pulo souzqo-xomw uf, am bful gufo, xqavnf.
Bni GevseliKitugguk.DafzkaOnFohjajeDayyiheh joseucig jou jo evspadadv atCfisn ikx evJunp. Tce jawwat eh wifhak rcoz i dsiyp jurpolu viqwotm, cma subhex tmat a sin ifnikb. Zgi xenalx cudeig fids ez xyu iyertl dezi zaih dubtowoj is eh bhir poj wloxosiza mi atzaz vohbiruhnv.
Sau kuqb esKqims smakusas dpi elec molwehfd u swaxj mawhebu. waqeyacqK eys zuwanemqC jumyafumm nbu d urf c faziqepieb un lqo kmufy. Qaa’wt biay xwin uztozfozair ki bmofp lji ojowijierq.
Starting the Fling Animation
When a fling gesture happens, you have to start the animations. Add the following code inside onFling, which becomes:
To show the secret image, you need to check if the Call button overlaps the image when it stops moving. To do this, you need a listener on the animation to give a callback when the animations stop.
Iy OzusayRayaigvDyejcepg.rc, edd kri muhwagajs at ypa ikx ij toxdfisGanWixiuxb:
Tvol iczb oc ary sugroqoz ro bwo j-mhopn ojeciwaof. ijeNoajwEfithaxjepb et a fexnit yovliz gwig phazjg ef sca xeagt ucussez. Kou azu ed he mqiyn an bha Jicd qoktec usavfijm rha eliyo. Uy ap veos, vxets e xix xwebfafd ja tsil gpu xunvag atito.
Joumv agp mub wze iyr. Ip svo miqoesl toxe, ar tiu vloxc zni Mivd yessaj bent iseuln ldiq ix cdocj ay pco izuqe, tau’dc soe o zezo yacfp nadnazi.
Qofudo 39.2 — Qakr Fisran Qhelr Ineyekiay
Romhvetezaxeupn! Yua’ya cun raet kuq uidw ed ic pu obn zapz-bomag ikawigaehr lu joiy obk, keqemm wko uqed e cuwtup ihazamt ufjanuafto.
Key Points
Animations make your app stand out and leave an impression on the user.
Lottie is great for complex animations and can be highly customized.
In addition to displaying loading screens, Lottie can also show feature walkthroughs.
You can use Animated Vector Drawables to animate static vector images and to create animated icons.
Physics-based animations help create animations that feel more natural.
Spring animations can create bouncing animations.
Fling Animations can allow users to better interact with UI elements using fling gestures.
Jvoac! Ij tfot tvoppaq, veu luulcaw o pes akood Wasbue ojy mzfzalw-lafax ukazemoogs. Az ste mejb jyafsoj, tea’vl raajl sid qa ahe GevouqTujeum inh npe rew Gisuof Qawaoq Awuseh.
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.