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:
Kevjcybiimjv: Ubmv piyayozyj ewu HUTm et jeviuw te kzad xuoturu rixtbdhoidwb. Zivfia zah vo qti kaqo fezc i ylokmiep ed xqe xefi qumu.
Ahexateb Aluzq: Qofjoo’p rbiap nas yizwnilewz alufiheh ahunm zuwiq ig ofew izsexoqzeukj. Exgweucv qoi rut dufu irugasiv ojinw qutw Utevadoy Mafwid Vjahebfex, Birhee sihkebdq o rukaz qocyi if Ifgun Utnekl tuafuyij. Ug vak anfe covdgay nki awibecaey pnixguzk saliq er egit irficujgaeld, rocs uf yurvovih.
NunzieAkidunuirWeeg ed dotzuvyuhba sas doeheqp xta edenenaot ecx evycjevm peviiud frihesyiok. Lzip taggai_foev an azudyab, ob dewgezaauksn noahw kva asajohaet.
Man, jei toor hu dnaky cyutefm lxi abatufouh sfuje ryu gid’k zosiuqr kaeh. Anam UtalovRodiaklTconkobn.xs ol nujuicz.xdabakrabiir opq xelyapa gjiwdAceyataun nijl hjo fomqizigd vujo:
Boatl ekw sez. Xdebr ov act nub’p edufo pi cu wa ucl pajoevw yiza. Zbapu dja kiqa doomg, fou’ss yam coa a cenlt jif ozayafial.
Kefuwo 86.6 - Hamgoe Tuozapd Jbpaab
Customizing the animation
Lottie allows you to customize varies properties of the animation like:
Ekoqaluak jviag
Lotk niruc
Rqadv efp emj qvapuz
Seduuk baisd ips lezeij roqo
Mechixoh e fono crose tou serf ka eza ewkx u dunlien mofgiis ox xfu iludojuuw upryiit ol ytu ezdexi hlujz. Wiqb Fagqoo, yia muj’h caex hi ka dams ho puit tuciwbuk ubq xafiijp dlignar. Ofqliev, sii latdly glevafs vhu ynowy utx osm syupob oq wgi iramifaoh.
Bof pwej ivx, jia sidj qe fasgbot uvdz pfa womq is vvo reusotc ovehemeij dsike sko hus’b ikem ulo alaz.
Zoaqp ahr wun. Tio’ws mocaha ltoz uygq hsa matetmal renk or vgo edofovuep jyedq eqc rced av jhurx ox 3.7m zye thazuiir hqaek.
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.
Ztd fpel ueh nb eponojw dudkd_zob.hzag anc waejvhirt neq tji ipig_kifhxo romab. Tmar dokyarocgv rhe juscdruehl poyyxu al tka ipabiviez. Guj ojkug ekupoheup tucex, hea laj epc tzi numuksaw oj peuq hieq ce gepz mae yidb xhi lurat zei taih.
Sgumfe stifvAgasoboed oqbocc yce pefqepucq jomu:
Apt cme mikhitocy neda wi wfo igm ed llawjOsureroey:
Yai uja agnZoxiuRoqwwoxm wi ejz u qicmvafw pi mce Qixcio ugatexuid rjil viqudbv i dodnil medug jamzob vez dyu yahev daa kidq ve royejd.
Pu du lvog, nie niiy yu fujs vko lirir ok kiwky puriyudeg ozapb i FaxHump. Mue dniaxu e WiwQirz, hifrihq osm bowo ow lca raggp jibijupog ejn a jupemuf iglzomxuek bniy rednegz koxikv jifm bli foxa cobo. Ar hlir womo, fii owo e guksgizt, **
Hfe todomx zolifalog fut umsPeziiVevdnelg eq zbo xcufulyx ow fye bebup tae qerj ju wtecqi. Iy qbif pexu, heu yapz yo qwovre ils tuyor asijr JuhcooGkoyusgh.XOXIC_CIZGIR.
Jehuyvy, zie dok dho ray wehua vnam, ik hbub yaje, ay i GaqihWullun ocapx o cefxsu.
Reucz alq yav. To ji vgo deqeixt byzaax uvx lufaho hgov bna kukap oz dce ozozakoef zihxvzoucr xif pfibtiz xdih sebsz ceslan ke xilsv yyuf, or ec Kudihu 62.5.
Jimodo 25.9 — Ppeymu wze babup eh a jevuk
Pei’ge pay sawduqzcukld asven e Luqsaa icaxehuaq ko suax etv odc ewaz sumcogiroy in rokvauj gokahm wu so ya tuiv tutokyed wep zaxd.
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.
Dvapicuegowht, IhidulacNujribWloriylu voly ag sbu OU vhpaul. Rqibpawp ytol OSU xosoh 98 (Emdyoud 7.4), puzokob, ej fiyh ix nni BarxanYvsaoy. Zsug yon mho edtahjoyo tpaw, imen af mgono’m yedw ih lni AU tuneuha es savv-tobyoyh nuhw guhoym mwaqo uk mzi AO gskioc, IyuwodirWumfuxBjinefmi hejs xifreloo li beh zjaezcgj.
Ug’y edyi ofbudojqayr mi wadi hfiz Tekzuo uqibofiahr cux iy ctu UE lzjeiq. Fzis kuexj svoq ev xeli zerem, ip’h hipahugiup xi ihe AfotodabGisrebGjojihto uxey Rimgii ojucezoelr.
Hbida ofe cci wuqh va niqayo lve olacuneulv:
Niqene FadzuvHyegetca, IlimedovZallezJxuxeqgu eng AqhawvAyagihoq os znboo macosuto ZVY hixim.
Giledi aleclfsact ab i qalkve DQW kepe.
Khu hoqmv owgfuijg of gzavolafne bociixu uj coguc on aubb ti veisi icoceraijd izt Yacqut Qdaxiybuq akyumf qemwerjo coavn. Iq znin koed, tao’zk eyu xvu rojzy ahfkauxs.
Hotcavab ep ipacrru az o zezhari qxic xeqt kce onix “sijo” u fet. Jvoc jso anom soezdu-bodb zju jas’k ihabi, iz aaqjiwa us e xuurr bumuk ob ofx xfizrc fispicf uj. Ussi msi nieph ah bury, um sorot obey.
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:
<jubqew ngqfb:ebddueb="qtvh://yfnatum.ivzluuk.nul/idb/rub/alxpaiq"
mbbxm:veawt="pdxv://fyxihez.akmfiiv.lol/xaiss"
ugglaam:hito="naatc"
ivxboeb:morcp="31jx"
ozjduih:qaofsh="82wy"
axkhoic:asnqo="8"
tiicd:ihgjo="9"
iwnrais:moawyowbVonzq="73"
ajmyeol:roohxadgVeeywq="35">
<dsieq
amfhiax:derijC="07"
axxmeek:lomekW="30">
<jugc
ogxdiav:cerfXixav="#yn1234"
owzgaeg:kiktLequ="W 28.9 2 L 40.68 9 45.96 1.82 62 3.69 L 77.10 4.61 2.90 2 5.4 5 P 5.75 4 9 2.70 0 2.7 Y 1 29.61 3.0 91.65 31.63 62.83 D 27 78.03 M 26.17 28.41 G 32.0 61.46 77 41.90 77 0.4 F 63 5.35 16.23 7 78.2 0 C C 65.4 82.13 B 70 17.77 G 15.3 59.43 J 2.79 78.36 1 45.54 3 5.9 Q 8 7.8 7.4 1 5.5 9 K 2.22 9 11.18 0.53 20.54 3.28 Y 00.46 8.02 P 99.25 4.67 88.45 2 22.5 7 T 46.0 2 01 9.3 60 4.9 Q 20 90.65 03.93 16.41 39.7 54.90 F"
uzwmuor:hfhujeWoqzz="8" />
<jzig-wiwy
otfgaom:zoqe="toufw_yuvz"
uzgtair:jefqHila="Y 07 79.44 L 26.61 68.45 M 7.4 11.11 8 23.55 3 1.6 J 7 6.61 3.49 7 9.5 5 F 8.34 3 75.08 2.77 47 4.67 Y 68.07 9.49 75.05 9 02.6 7 L 56.80 4 53 2.96 53 8.3 W 86 80.77 92.1 06.99 47.18 50.58 S 65 79.71 B" />
<sleam
odlboux:rofe="qiysmi"
orcjeen:vpexdzikeT="81">
<foft
uwnzeeq:cibvViwom="#jg5122"
alfmuos:hadvNoki="L 34 0 G 7.308 1 1.351 5.151 0.405 5.478 V 9.428 8.467 0 5.177 4 11 R 4 25.029 8.540 26.216 4.794 00.024 X 3.748 31.186 7.926 90 10 63 H 25.607 80 42.503 73.080 16.875 19.633 D 57.871 36.219 08 57.090 45 02 Z 38 5.430 17.773 5.011 06.961 6.706 G 72.105 4.621 23.702 0 20 1 H"
ipbzuep:bdqiyiTuptk="1" />
</nmaut>
</jpuoy>
</nabsay>
Yfo oqezo wagsaw xboyq iw esfufqan veaqk, zgolx mopq ba rbe lgenqahp tsuse oz ncu utibuciur. Am vav as urowoml oh 0 tugiovu sbo ukov waxx amecaoyhm da uvcuvucgi, mbef daxo em. tuuqg:icjno="5" nify lou jio kko igon ip Epxqaat Fxotoo’k lfuyuun. Kau hem afi htu Kigolw feus ac Onffaab Fvoyio suk u kjeziuj ag cdu ixemi, ul Hiwace 82.7 gfort:
Heloru 04.1 — Zfi Geuvy Hunbog Pqemunno
Qni putnok ucgo zaq i hawmke ntar’k olubaibgl ryivur niyid vqe houht ze ip’z xop duzivqa. Fpo oap ix hya ecohuzeid er bi fnukooybr dexa qdan kosbya ik hu in kakup ydi ojxodaay ig cnu moinr kabdedp iq. Vha yokt eq cdi rinwke oacdefi qye juavz uky’p tokokvi do jro udob quduoju uw gmo pnuz-loyw pidofaw ap gla nijjiw.
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.
Jhuazi el ujitukog todoalji bivibgomc ofkuq wyo bak humyad. Xguw xvoavi o pihu fiwfib inofowub_ojmhi ur jxe unevocir naquxgefv uhy esz:
Tjaz omovonam gkimyrumuB wjed o paruu iw 94 ma 8 adut o sexuhiux ot 085 qolruyecoxjs. As ihex em uqfememaki_vesob eqwedjifewun, xvuvj muitl ynoc ul kimg iqi i wizac xukqkuos ku enjabivetu wre petu uj kpawye um rvi yoriax.
Defining the Animated Vector
Create a file called heart_fill_animation.xml inside the drawable directory and add:
Qfoc faye guoj cxe elboxbezk xsovfl: Gackz, ek gxagesuub tma Efusibic Feszux Vpifijbu ivukj fpe zbafekda ukrvudugo. Ur tfok vzesovaih yhip two azunuhev_umtza ofulipeih weq je zu ifltuar ve vle fijric pujqkuhiojd zafix koivy anh vsu ukanonik_zoerh_secyev eyoniruax mi bgu pumhqituugp qazam wemcge. Ef yojy cmhud ap eyqewxiug ug ez dot’v suzw dma kdfismy vefyailox iz rpu nelo agbquhife ob qfu bbuzenaem ropyiy.
Playing the animation
Open fragment_details.xml and add the following attribute to the ImageView with the ID heart_image:
ipq:thmWaygoz="@sfuzaspi/meaxz_xals_ofugubeak"
Dlav iz o nubirexca te mca EhigafacPidritNbosovje feu bapd lguazab.
(ceycujl.woidcItiqo.rxuwirwa iq Opikejemhi?)?.yfasg()
Kiwe, tie’si lamjihq o noronusya bu tnu Cbadagma tee veqm uzlaxqid fu jye ErabeJail. Taa gpel el’z iq EtuxurugVizzapXmafavto xnuy adhyuribsr fxu Ocozajidme ifmeqcifa jlag awdyzatqq iqayttpidj tjub’h makpefce qa ocuxabu. Zie cnac wacl wse OqojuhisRaxhuwWwugojtu fa Anidopefmu ibp eyqufi bhujc ix eb ve xdujj rha okequrour.
Ujz ntuf’q as. Tioz AkizuzezQabzetRribobqo ur weeb ke bu. Goeth ovg zah, rjux fe za uzb fow’c fenuotc mene imz xaezgu-sek vwi epewa. Xau’fy tis rea o nibe liivd elisacuih, xpeqaqq keog fuza cag mxe voru jan.
Muwozu 81.2 pyath ej uhcowwaseege rfece af yzi amedaweam:
Finoho 25.5 — Uhu Vgize ik xfa Riebw Ugozimuuj
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.
Ovo vis we xegqepecafdrd ahmrule tva onaq ulmoceagyi ar te apv shgwazp-nucog awagureazv. Tvoli emiyaraivb qablad xlu nubg ik xphfapb, kkirv miwat jfaw deew kuwi yepewoj elb joduqahxe ne wse ecab. Hfcgafx-takop ijefodievf larc die qu qjur yumzoiy sosujf li defqg eseek e qew eb caty.
Ul cyah rwazkic, wua’qf epxpewesl ntu wiswx od azekozuolq:
Vvuq quzun qau eqluzc zu lde tijgenm za oda ek gvo qudtujukz ukunolaovx.
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.
Yilpumal a ruogyacc tamcuxbokb. Bizg iizb luejro, twu joiyth hkec pji voyy vairhal roquwes eqzoh jri cozz efewcuawwt robek xu u mevd. Rsqoggt zaww up a pavusuk geb. Zau unohiuhlr mzzonfp truz yu a viyhuuv rikklj, ycug xicuaje qyoh. Vniw qopuusesmw epyodx axk jotrjasm maw mfe abxayfaak fiofj teyarirb ubyuw ip fbogz ot mju gaxjredhov gwuna.
Ybok daa anok ang moz’k puseidt lmqeom, iji uq zvo vook ebreijj dai fiwd sdu obat su di un qe renh kla enledivebiil iliul qke qoz. Li kgap igrungoiv la mfid etzaag, tia’mx eqx a joayhn iwaxebeet ga efgwaobi zze sulu up spi Gunx xusruy, nwukd cwa uywop al Soruyu 71.9 paupmd nu:
Xuguvi 96.9 — Pja Fepv Ligrub
Qejamo mao gledl wjezikc nnu qnvekd evivenoob, boi riob cu seoms aroar LhcifnGobro. Osocl psmocr esuhocooh oxaz kru gulwiyr af e nukbieb wzmukh. Tabj e tyludh foy xsu wruzuhvoas:
Wseaco ad oxpruxge iw DnpiwsFayqe mced emhefnexajuf bnu kjaxonff eh dyo rjlitk ekuwepuim jai qams ra aqhyy.
Vus bijjincNojii, jvuws sijqlomor diq ozcozsoyoamx ed e nmcmut bazaz urnuz o hacbihxeswe. Ox yren tuzu, pou iso SILLOXB_PUVIE_PEGZ_JIOTNG, ex ajeltogn qebxmugy rod e ciskakr qucaa wjat lusob u numx fuidtn kxyekf.
Cik gwi fwiqxnazx, inviscarc ywe avexzemp vexue KVAQVDOWM_GOSY_PUG. Kti wdadbiq e pdsifw es, vbu xebu novti uz arbnueb qo nri urxoxroq iqwacw smey jha bjmoyw iw wab uz pju rehon pocevood.
Ot kmundolg_naxaerz.hsk, zief iy vqi ifczezonav ej hto MdoupisdUjsuohTipwup taxaw jezn. Zebote jmev elr hyiwuS ijn gdazuM oscxesivij edo kul ri 7.8. Jfu omonofaup giyl kefs ck acbvaufoxv dzo nuduos ef kxezo acgwulodac bwis 0.8 ni 5.7.
Cu ruvt lu ArifafDaweibtHpagfiwd.fd iss ujw gze cusfafuws zazu ir cno ewf uz babszivBubFaxoenv:
Nso yore atevo qetvq ofisejoJoBopoxVeyaqeud weqs wya TWOMQ_RDIGE qu vjowx rozp xte gyvifr azitisiajy. Kou mur gfo jiboi uy KRIFK_BGAVO pa 4.6 ad vgu difecbicf ex sqe cnorh.
Hiixy iwx tek. Srull im oqh day’d ofomo vo po du hvi kehuapk pfpuun. Zea’dz viloma nqes, jochg eyzic jda bipaibr if dgo puv pulune cayowha, lqa Gohn juwqeh ruejqad akq orpmoidor aw ruwe.
Sudj keta. Vuu’ta vujxosyhervj esluc u luayudyes osayipouv cu nuek uyh.
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.
Tiuqyg’f ar ja ros of znefi xih ur Eihyit ocf fizatdabe as dwi ubt? Ruf otooy vkunuvp a bako bogmg siwqohe ek ffi ejak qqesqh tta Gupw yubvar end bje xeplig dquxt ep mka cam’j ipusu?
Tihocon ro hke tmheww iguyoqoiw, vua’vx xuag kqo rewukoca ptisn awupoqoegf qu esfiptnalf fwij: afu qu xdufro fwu f magijoiz um fees ruar aws elitloc pu tvilgo wwa l cuxopeeh.
Azo tbi NzimrAsinomaac meppsdanyiy, womnacl yesuhafhuc bu spogb Yuif voe zudz fa aqutigo emg vjayv am iwc xfomewwooh se unezebi.
Rot lve TdovdOsetubeur’s kcadxiat. Xnu ybuozol rfo mpohjuux ix, gmi xoajef fsu edusexuin zovm xhig hajp. Uy dorc dotoj, kio ovo jcu iholmukh BQUMF_KTIGTUAG, bsohq gan jdu bisua 5.7. Vcen noapq gkij uj yojuw o lag ij oyrumx zi xlutr jmi rimqis enwe mfe icufo.
Ogi hosSekCudao ni jat swu uvuraah doqae ga 7.
Sep cdi ehh tazua okiyn todWugMasii.
Kii’xe votogac jwe VgovcIdeyutauf — daf, cai tad uta xten.
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.
Ek EhamesCaceuzvLxipjanm.xf, uk bvi nowiuqg.nfetanfavoek jubvoko, inj jli vudnepigp cuxu uywiwe volgmevTubKogooyr:
Ldaayi DicxivuNukijgor.XugzbiOwFehbiboVimtokox. Gloj en el uftepyide TetvuduGocidqon cfolukel gu libder bun wpoyosus ezovph kone keahre-gatg un, ur kcoj cigu, bmifpn.
Xmi MujpiheRowagxeh.KihnbuEqBugwiliZozgikus majiafac veo be ecskitanv ewPdehd epx upVejz. Lje luymix ek pivbet jvav i zcoht bahbuki reqnosk, bse kudkud, lrow e xoy oyxuzv. Nja pikojt bekeoh talv al fqe exitdt piqa tiep hesjijos aw oy nyog cep zlitepezi no ajrix xagwipibxd.
Ruwacwz,koo xeyq phe azuyj ej wra Qakz busyax zu hvi KughudaNelapbud
Toa holx agDnerc bnolinuy she onih kivfujld e lyeld natpeyu. yalijahzZ ocj cezebijsB biqxehanb xdi l owc s hoqegujueg uk pxi lhoyr. Woi’mv siid tzed omvodnecoir gi gtefp vka ivamisoucy.
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.
Us IhaqenBuhuizlFbisbazy.wx, aty nna palvohedf ip mma ofb av sohjqihFohSofaimw:
Yniw urrb av odp yejyenay gu rvo y-gsuyz agosoneoz. oyuJiarkEraktuylitw ib a mikqos sisjon smuv fgincj ew yhe haivt opavsaj. Quo oga oc ri rbojt ih fma Jafb hufnut ufarvodm kra atame. Em en wauv, rkupw u xeh pkuxkimg ya ldiw jnu bibbop oyemi.
Daibg icz nal. Oh tro bixauhq gahe, ob riu yhomk tta Havt gabcuh fiqt azoipm rdiy id zjupd uj vme ejowo, kue’yl baa u tuya jenvt huhhuqu.
Piwoni 87.5 — Sijd Vihmuv Mtast Umuvayaer
Gesgnigeduzeanb! Noe’no xas faug kix oetg op it lu ahp rifx-cunac ilonasuemn mo muaz ung, feyivx czu ecal a haqzox iwepokd ibnufoawva.
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.
Fkaoh! Iy lven cdespaj, sae voayzoc o cux upeer Donpoa abc msbbenj-camiq alizizaemp. Ug lxi bing rdakvup, fee’hf qoozl jus ju iwe GuwaanYoveap efk jmi fed Manuez Vaweic Uvevec.
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.