简体   繁体   中英

Android fresco library gif not animating

i am a newbie in android. Below is a sample code that I copied and modified slightly but it is not able to animate the gif image . It just shows up as a static image in my app. gifImage is not animating. I even tried to initialize the controller twice.

    private void findViews() {
    button = (Button) findViewById(R.id.button);
    sdvImage = (SimpleDraweeView) findViewById(R.id.sdv_image);
    roundBorderImage = (SimpleDraweeView) findViewById(R.id.round_border);
    circleImage = (SimpleDraweeView) findViewById(R.id.circle);
    fullCustomImage = (SimpleDraweeView) findViewById(R.id.full_custom_image);
    gifImage = (SimpleDraweeView)findViewById(R.id.gifimage);
}   DraweeController controller;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fresco.initialize(this);
    setContentView(R.layout.activity_main);
    findViews();


    final Uri imageUri = Uri.parse("https://lh3.googleusercontent.com/-voUmhKJzNHc/VSJaPfSJ2pI/AAAAAAAABKw/-oFVzRZxI40/w140-h105-p/fresh_green_grass_bokeh-wallpaper-1024x768.jpg");
   // final Uri imageUri = Uri.parse()
  final Uri gifURI  = Uri.parse("http://s3.amazonaws.com/giphygifs/media/4aBQ9oNjgEQ2k/giphy.gif");
     controller = Fresco.newDraweeControllerBuilder()
            .setUri(gifURI)
            .setAutoPlayAnimations(true)

    .build();
   // mSimpleDraweeView.setController(controller);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           // sdvImage.setController(controller);
            sdvImage.setImageURI(imageUri);
            roundBorderImage.setImageURI(imageUri);
            circleImage.setImageURI(imageUri);
            fullCustomImage.setImageURI(imageUri);
            gifImage.setController(controller);

            gifImage.setImageURI(gifURI);
        }
    });
}

Can you try with version 0.14.1? The following code works for me:

Gradle:

compile 'com.facebook.fresco:fresco:0.14.1'
compile 'com.facebook.fresco:animated-gif:0.14.1'

Somewhere in your layout:

<com.facebook.drawee.view.SimpleDraweeView
     android:id="@+id/drawee"
     android:layout_width="46dp"
     android:layout_height="46dp"
     />

In Java:

SimpleDraweeView simpleDraweeView = (SimpleDraweeView) findViewById(R.id.drawee);
simpleDraweeView.setController(
    Fresco.newDraweeControllerBuilder()
    .setImageRequest(ImageRequest.fromUri("http://s3.amazonaws.com/giphygifs/media/4aBQ9oNjgEQ2k/giphy.gif"))
    .setAutoPlayAnimations(true)
    .build());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM