【问题标题】:How to create a frame-by-frame animation using svg in native android app如何在原生 android 应用程序中使用 svg 创建逐帧动画
【发布时间】:2013-07-24 11:54:21
【问题描述】:
  • 我知道 android 本身不支持 SVG。
  • 我选择androidsvg 来显示svg 文件。这个库不支持 SVG-buildin-animations,这没关系,因为这不是我需要的。

我已扩展 RealiveLayout 以将 svg 添加到视图中。这很好用。

public class Graphics extends RelativeLayout {
  public Graphics(Context context, AttributeSet attrs) {
      super(context, attrs);
  }

  public void showConnectedAnimation() {
    //TODO: show animation     
    SVGImageView svgImageView = new SVGImageView(this.getContext());
    svgImageView1.setImageResource(R.raw.shield);
    addView(svgImageView);
  }
}

问题
我的目标是有 10 个小 svg 文件作为逐帧动画。 我更喜欢使用android的原生AnimationDrawable,但我不知道如何绕过animation-list.xml

可能的解决方案
有没有办法为 AnimationDrawable 动态创建动画列表,其中填充了使用 svg 库中的SVGImageView 动态创建的 ImageView 对象?

任何帮助将不胜感激!

【问题讨论】:

    标签: android animation svg frame


    【解决方案1】:

    您是否尝试过使用 Canvas 在某种 SurfaceView 上绘制 svg 形状?

    【讨论】:

    • 我已经阅读了解释画布用于需要经常重绘的图形的文档。 (主要是游戏)。就我而言,我有一个静态循环。我想我可以自己使用计时器和小尺寸画布为循环编写动画,但这对我来说似乎有点过头了。
    【解决方案2】:

    我没有尝试过,但看起来您可以使用 addFrame() 方法将帧添加到 AnimationDrawable。

    类似:

    ImageView imageView = <get from layout XML or create it>
    
    AnimationDrawable anim = new AnimationDrawable();
    
    SVG svg = SVG.getFromResource(this, R.raw.frame1);
    anim.addFrame(new PictureDrawable(svg.renderToPicture()), 10);
    
    svg = SVG.getFromResource(this, R.raw.frame2);
    anim.addFrame(new PictureDrawable(svg.renderToPicture()), 10);
    
    .. etc..
    
    imageView.setPictureDrawable(anim);
    

    【讨论】:

    • @A M 还没,没时间。
    【解决方案3】:
    AnimationDrawable anim = new AnimationDrawable();
    
    SVG svg;
    
    svg = SVGParser.getSVGFromResource(getResources(), R.raw.frame1);
    anim.addFrame(new PictureDrawable(svg.getPicture()),500);
    
    svg = SVGParser.getSVGFromResource(getResources(), R.raw.strokes);
    anim.addFrame(svg.createPictureDrawable(), 500);
    
    svg = SVGParser.getSVGFromResource(getResources(), R.raw.transformations);
    anim.addFrame(svg.createPictureDrawable(), 500);
    
    svg = SVGParser.getSVGFromResource(getResources(), R.raw.gradients);
    anim.addFrame(svg.createPictureDrawable(), 500);
    
    //so on
    
    imageView.setImageDrawable(anim);
    anim.start();
    

    【讨论】:

      猜你喜欢
      • 2020-02-29
      • 1970-01-01
      • 1970-01-01
      • 2022-07-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      • 1970-01-01
      • 2011-08-30
      相关资源
      最近更新 更多