How to use PAG animation in Android?

16050235:

How to use PAG animation in Android?

  1. Import dependencies:
  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'

  1. PAG file storage location
    insert image description here

  2. xml file

        <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>
    
  3. java file

      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();
            });
    

Guess you like

Origin blog.csdn.net/qq_43867812/article/details/132040880