Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Dynamic Image

PonyCui edited this page Dec 19, 2018 · 1 revision

You may replace an element in animation file like this sample.

Download Sample File

You can download a sample file from SVGA-Samples to try.

Step

Load animation as usual.

// Setup a SVGAImageView by yourself.
try {
    parser.parse(new URL("https://github.com/yyued/SVGA-Samples/blob/master/kingset.svga?raw=true"), 
        new SVGAParser.ParseCompletion() {
            @Override
            public void onComplete(@NotNull SVGAVideoEntity videoItem) {
            }
            @Override
            public void onError() {

            }
        }
    );
} catch (Exception e) {
    System.out.print(true);
}

Setup replacing Bitmap.

try {
    parser.parse(new URL("https://github.com/yyued/SVGA-Samples/blob/master/kingset.svga?raw=true"), 
        new SVGAParser.ParseCompletion() {
            @Override
            public void onComplete(@NotNull SVGAVideoEntity videoItem) {
                SVGADynamicEntity dynamicEntity = new SVGADynamicEntity();
                dynamicEntity.setDynamicImage("https://github.com/PonyCui/resources/blob/master/svga_replace_avatar.png?raw=true", "99"); // Here is the KEY implementation.
                SVGADrawable drawable = new SVGADrawable(videoItem, dynamicEntity);
                testView.setImageDrawable(drawable);
                testView.startAnimation();
            }
            @Override
            public void onError() {

            }
        }
    );
} catch (Exception e) {
    System.out.print(true);
}
  • A Bitmap object is also available for setDynamicImage first argument.

ImageKey

The imageKey is the name of png file, ask your designer tell you the file name.

For example, the layer png image file name is xxx.png, imageKey is xxx. File name should always use English name, do not use Chinese or Japanese etc.

Clone this wiki locally