Including a .gif in android project

2020-05-06 10:38发布

my question is how can I attach a little gif with fire to my bottom of my spaceship in my game.If you have any ideas,i'd love to heat them. Thank you!

标签: android
3条回答
相关推荐>>
2楼-- · 2020-05-06 10:51

I would highly recommend you to use a new Fresco library (made by Facebook). It handles all kinds of image loading and it's highly customizable.

  • Fastest to play gif (faster than Ion)
  • Easy to use

Include this dependency into your build.gradle:

dependencies {
  // your app's other dependencies
  compile 'com.facebook.fresco:fresco:0.7.0+'
}

Here's a link how to setup Fresco: http://frescolib.org/docs/getting-started.html#

To play gif you should do something like this:

SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.gif_draweeview);

Uri uri = Uri.parse("res:///" + R.drawable.gif_animation);
DraweeController controller = Fresco.newDraweeControllerBuilder()
            .setUri(uri)
            .setControllerListener(new ControllerListener<ImageInfo>() {
                @Override
                public void onSubmit(String s, Object o) {

                }

                @Override
                public void onFinalImageSet(String s, ImageInfo imageInfo, final Animatable animatable) {
                    if(animatable != null) {
                        animatable.start();
                    }
                }

                @Override
                public void onIntermediateImageSet(String s, ImageInfo imageInfo) {

                }

                @Override
                public void onIntermediateImageFailed(String s, Throwable throwable) {

                }

                @Override
                public void onFailure(String s, Throwable throwable) {

                }

                @Override
                public void onRelease(String s) {
                }
            })
            .build();
draweeView.setController(controller);
查看更多
Luminary・发光体
3楼-- · 2020-05-06 10:52

Hi use this link get a library
https://github.com/koush/ion

ImageView animatedGifImageView = (ImageView)findViewById(R.id.animatedGifImageView)**strong text**;

Ion.with(animatedGifImageView)
        .fitXY()
        .load("android.resource://" + getPackageName() + "/" + R.drawable.sampleGif);
查看更多
时光不老,我们不散
4楼-- · 2020-05-06 10:59

Try a WebView

public class Gif extends WebView 
...
public Gif (Context context, String url) {

      super(context);
      loadUrl(url);
}

And then:

Gif gif = new Gif (this, "pathtogif.gif");

setContentView(gif);
查看更多
登录 后发表回答