Android壁画库gif没有动画

时间:2016-10-04 10:50:24

标签: android image animation gif fresco

我是android的新手。下面是我稍微复制和修改的示例代码,但无法为gif图像设置动画。它只是在我的应用程序中显示为静态图像。 gifImage不是动画。我甚至尝试初始化控制器两次。

    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);
        }
    });
}

1 个答案:

答案 0 :(得分:3)

您可以尝试使用0.14.1版本吗?以下代码适用于我:

摇篮:

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

布局中的某处:

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

在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());