As a third-party framework, the Pag animation framework has similar advantages and disadvantages to Lottie, so I won’t go into details here. If you plan to use it in your project, you must have gone through some research. The Pag animation framework is divided into several versions, some are free and some are paid. The community free version we currently use is only used to display Pag animations. The advanced version can play videos, sounds, etc., choose as appropriate.
github documentation:
https://github.com/Tencent/libpag
Introduce dependencies
// pag库的库
implementation 'com.tencent.tav:libpag:4.2.100'
/// pag的依赖库 必须添加
implementation "androidx.exifinterface:exifinterface:1.3.3"
Obfuscated configuration
-keep class org.libpag.** {*;}
-keep class androidx.exifinterface.** {*;}
Use PagView
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<org.libpag.PAGView android:id="@+id/pag"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Add files to assets
Java/Kotlin code
// 加载Pag文件并开始动画
findViewById<PAGView>(R.id.pag).apply {
// 把0.pag放在 assets目录下
composition = PAGFile.Load(assets, "pag/0.pag")
// 无限循环
setRepeatCount(-1)
play()
}