FLog.setMinimumLoggingLevel(FLog.VERBOSE);
Set<RequestListener> requestListeners = new HashSet<>();
requestListeners.add(new RequestLoggingListener());
f、内存缓存配置完整代码:
package com.facebook.fresco.helper.config;
import android.app.ActivityManager;
import android.os.Build;
import com.facebook.common.internal.Supplier;
import com.facebook.common.util.ByteConstants;
import com.facebook.fresco.helper.utils.MLog;
import com.facebook.imagepipeline.cache.MemoryCacheParams;
/**
* 内存缓存配置
* https://github.com/facebook/fresco/issues/738
*
* Created by android_ls on 16/9/8.
*/
public class BitmapMemoryCacheParamsSupplier implements Supplier<MemoryCacheParams> {
private final ActivityManager mActivityManager;
public BitmapMemoryCacheParamsSupplier(ActivityManager activityManager) {
mActivityManager = activityManager;
}
@Override
public MemoryCacheParams get() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return new MemoryCacheParams(getMaxCacheSize(), // 内存缓存中总图片的最大大小,以字节为单位。
56, // 内存缓存中图片的最大数量。
Integer.MAX_VALUE, // 内存缓存中准备清除但尚未被删除的总图片的最大大小,以字节为单位。
Integer.MAX_VALUE, // 内存缓存中准备清除的总图片的最大数量。
Integer.MAX_VALUE); // 内存缓存中单个图片的最大大小。
} else {
return new MemoryCacheParams(
getMaxCacheSize(),
256,
Integer.MAX_VALUE,
Integer.MAX_VALUE,
Integer.MAX_VALUE);
}
}
private int getMaxCacheSize() {
final int maxMemory = Math.min(mActivityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE);
MLog.i(String.format("Fresco Max memory [%d] MB", (maxMemory/ByteConstants.MB)));
if (maxMemory < 32 * ByteConstants.MB) {
return 4 * ByteConstants.MB;
} else if (maxMemory < 64 * ByteConstants.MB) {
return 6 * ByteConstants.MB;
} else {
// We don't want to use more ashmem on Gingerbread for now, since it doesn't respond well to
// native memory pressure (doesn't throw exceptions, crashes app, crashes phone)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
return 8 * ByteConstants.MB;
} else {
return maxMemory / 4;
}
}
}
}
g、初始化Fresco
Fresco.initialize(context,ImageLoaderConfig.getImagePipelineConfig(context));
二、Fresco的各种使用场景
从网络加载一张图片
String url = "http://ww3.sinaimg.cn/large/610dc034jw1f6m4aj83g9j20zk1hcww3.jpg";
ImageLoader.loadImage((SimpleDraweeView)findViewById(R.id.sdv_1), url);
1、显示一张图片
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sdv_1"
android:layout_width="90dp"
android:layout_height="90dp"
app:actualImageScaleType="centerCrop"/>
效果图如下:
2、显示一张圆形图片
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sdv_2"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="15dp"
app:actualImageScaleType="centerCrop"
app:roundAsCircle="true"/>
效果图如下:
3、显示一张圆形带边框的图片
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sdv_3"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="15dp"
app:actualImageScaleType="centerCrop"
app:roundAsCircle="true"
app:roundingBorderColor="#fff3cf44"
app:roundingBorderWidth="2dp"/>
效果图如下:
4、显示一张圆角图片
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sdv_4"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="15dp"
app:actualImageScaleType="centerCrop"
app:roundAsCircle="false"
app:roundedCornerRadius="10dp"/>
效果图如下:
5、显示一张底部是圆角的图片
<com.facebook.d