본문 바로가기
안드로이드 자바

[JAVA][Android] 안드로이드 Lottie 사용법

by teamnova 2022. 2. 13.

이번시간에는 안드로이드 lottie 애니매이션에 대해서 알아보아요

 

 

 

 

 

 

Lottie 란 위 설명대로 어떤 네이티브 앱에서든 쉽고 높은 퀄리티의 애니메이션을 구현할 수 있게한 라이브러리입니다.

로띠에 대한 설명과 장점은 다음 사이트에서 더 자세하게 볼 수 있습니다. 

 

https://airbnb.design/lottie/

 

Lottie

Easily add high-quality animation to any native app. Lottie is an iOS, Android, and React Native library that renders After Effects animations in real time, allowing apps to use animations as easily as they use static images.

airbnb.design

 

 

 

자 이제 lottie를 사용해보자

아래의 gradle 을 추가해주자

 

위의 lottieVersion 부분은 최신 버전을 찾아서 추가해주시면 됩니다.

 

 

다음으로 xml파일을 하나 만들어 아래의 소스를 붙여넣자

 

<com.airbnb.lottie.LottieAnimationView // lott만 쳐도 태그 제목이 나온다. 바로 엔터 친다. android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="8dp" android:contentDescription="@string/nav_header_desc" app:lottie_fileName="header_lottie.json" // 사용할 로띠 파일의 이름이다..json 확장자까지 풀네임을 입력한다. app:lottie_loop="true" // 반복시킬지 여부를 정하는 속성이다. 반복시킬거라면 true로 놓는다. app:lottie_autoPlay="true"/> // 로띠가 있는 뷰를 열자마자 로띠가 돌아가게 할 건지에 대한 속성이다. 별도로 해야 할 처리가 없다면 true로 놓는 게 좋다.

 

 

각 줄마다 주석을 달아 놓았다

 

 

이런 식으로 assets 폴더에 있는 로띠 파일 이름, 반복 여부, 오토플레이 여부를 정해주고 앱을 빌드하면 로띠가 빙글빙글 돌아가는 걸 볼 수 있다.

 

로띠의 애니메이션이 끝난 후에 화면에서 사라지게 하려면 아래의 코드를 참고

 

 

여기까지 안드로이드 네이티브 고퀄리티 애니매이션 라이브러리인 lottie에 대해 알아보았다.

 

다음 시간에는 리사이클러뷰에 대해 알아보자

 

지금까지 스틱코드였습니다.

 

감사합니다.

 

https://stickode.com/mainlogin.html

 

STICKODE

 

stickode.com