壁画图书馆未加载任何图像

时间:2017-05-07 20:23:45

标签: java android fresco

因为内存问题,我考虑使用Facebook的Fresco库。

所以这就是我做的,

首先,我添加了以下依赖项,

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

然后我在应用程序类中初始化它,

Fresco.initialize(getApplicationContext());

然后我将SimpleDraweeView添加到布局文件

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

然后我在我的活动中添加了代码,

        SimpleDraweeView gif = (SimpleDraweeView) row.findViewById(R.id.imageMessage);

        ImageRequest request = ImageRequestBuilder.newBuilderWithSource (Uri.parse(url.get(position)))
                .setProgressiveRenderingEnabled (true)
                .build ();
        DraweeController controller = Fresco.newDraweeControllerBuilder ()
                .setImageRequest (request)
                .setAutoPlayAnimations (true)

                .build ();

        gif.setController (controller);

但它没有加载图片,我也尝试了不同的网址,但结果相同,所以我错过了......

1 个答案:

答案 0 :(得分:0)

我面临同样的问题,但不是用gif。下面是加载图片的代码,不要忘记初始化壁画。

       Fresco.initialize(context);

         SimpleDraweeView  iv_image = (SimpleDraweeView)itemView.findViewById(R.id.iv_image);
         iv_image.setImageURI(Uri.parse("your image url here"));

`

这里是xml

 <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/iv_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                fresco:actualImageScaleType="centerCrop"
                fresco:placeholderImage="@drawable/iv_car"
                fresco:viewAspectRatio="1.22"/>