如何在Android里面使用PAG动效?
- 导入依赖:
implementation 'com.tencent.tav:libpag:latest.release'
implementation("androidx.exifinterface:exifinterface:1.3.3")
implementation "com.airbnb.android:lottie:6.0.0"
implementation 'com.tencent.tav:libpag:latest.release'
-
PAG文件的存放位置
-
xml文件
<RelativeLayout android:id="@+id/background_view_1" android:layout_width="500dp" android:layout_height="500dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <Button android:id="@+id/start_pag" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:text="start_pag" android:textSize="40dp" /> </RelativeLayout>
-
java文件
playPag.setOnClickListener(view -> { RelativeLayout backgroundView = findViewById(R.id.background_view_1); final PAGView pagView = new PAGView(MainActivity.this); pagView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); backgroundView.addView(pagView); pagFile1 = PAGFile.Load(getAssets(), "122.pag"); pagView.setComposition(pagFile1); pagView.setRepeatCount(0); pagView.play(); });