SVGAPlayer is a light-weight animation renderer. You use tools to export svga
file from Adobe Animate CC
or Adobe After Effects
, and then use SVGAPlayer to render animation on mobile application.
SVGAPlayer-Android
render animation natively via Android Canvas Library, brings you a high-performance, low-cost animation experience.
If wonder more information, go to this website.
Here introduce SVGAPlayer-Android
usage. Wonder exporting usage? Click here.
We host aar file on JitPack, your need to add JitPack.io
repo build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Then, add dependency to app build.gradle
.
compile 'com.github.yyued:SVGAPlayer-Android:latest'
Head on over to Dynamic · Matte Layer
-keep class com.squareup.wire.** { *; }
-keep class com.opensource.svgaplayer.proto.** { *; }
SVGAPlayer could load svga file from Android assets
directory or remote server.
You may use layout.xml
to add a SVGAImageView
.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.opensource.svgaplayer.SVGAImageView
android:layout_height="match_parent"
android:layout_width="match_parent"
app:source="posche.svga"
app:autoPlay="true"
android:background="#000" />
</RelativeLayout>
The following attributes is allowable:
The svga file path, provide a path relative to Android assets directory, or provide a http url.
Defaults to true
.
After animation parsed, plays animation automatically.
Defaults to 0
.
How many times should animation loops. 0
means Infinity Loop.
Defaults to true
.
Clears canvas after animation stop.
Defaults to Forward
. Could be Forward
, Backward
.
Forward
means animation will pause on last frame after finished.
Backward
means animation will pause on first frame after finished.
You may use code to add SVGAImageView
either.
SVGAImageView imageView = new SVGAImageView(this);
parser = new SVGAParser(this);
parser.decodeFromAssets("posche.svga", new SVGAParser.ParseCompletion() {
// ...
});
parser = new SVGAParser(this);
parser.decodeFromURL(new URL("https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"), new SVGAParser.ParseCompletion() {
});
parser = new SVGAParser(this);
parser.decodeFromURL(..., new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
SVGADrawable drawable = new SVGADrawable(videoItem);
imageView.setImageDrawable(drawable);
imageView.startAnimation();
}
@Override
public void onError() {
}
});
SVGAParser
will not manage any cache, you need to setup cacher by yourself.
SVGAParser
depends on URLConnection
, URLConnection
uses HttpResponseCache
to cache things.
Add codes to Application.java:onCreate
to setup cacher.
val cacheDir = File(context.applicationContext.cacheDir, "http")
HttpResponseCache.install(cacheDir, 1024 * 1024 * 128)
Here are many feature samples.
- Replace an element with Bitmap.
- Add text above an element.
- Add static layout text above an element.
- Hides an element dynamicaly.
- Use a custom drawer for element.
Head on over to https://github.com/yyued/SVGAPlayer-Android/wiki/APIs
Head on over to CHANGELOG
This project exists thanks to all the people who contribute. [Contribute].
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]