fresco 显示缩略图,不直接使用setImageURI,防止卡顿和显示不全:纯黑色或纯白色

//显示缩略图,不直接使用setImageURI,防止卡顿和显示不全:纯黑色或纯白色
FrescoUtils.showThumb(viewHolder.img_avatar, item.getFromportraitpicid(), 40, 40);
 
  
 
  
 
  
 
  
 
  
public class FrescoUtils {

    private static boolean isInit = false;

    /**
     * 显示缩略图
     *
     * @param draweeView     draweeView
     * @param url            url
     * @param resizeWidthDp  resizeWidth
     * @param resizeHeightDp resizeHeight
     */
    public static void showThumb(SimpleDraweeView draweeView, String url, int resizeWidthDp, int resizeHeightDp) {
        if (url == null || "".equals(url))
            return;
        if (draweeView == null)
            return;
        initialize(draweeView.getContext());
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
                .setResizeOptions(new ResizeOptions(LjSizeUtil.dip2px(draweeView.getContext(), resizeWidthDp), LjSizeUtil.dip2px(draweeView.getContext(), resizeHeightDp)))
                .build();
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(draweeView.getController())
                .setControllerListener(new BaseControllerListener())
                .build();
        draweeView.setController(controller);
    }

    /**
     * initialize
     *
     * @param context context
     */
    public static void initialize(Context context) {
        if (isInit)
            return;
        ImagePipelineConfig config = ImagePipelineConfig.newBuilder(context)
                .setDownsampleEnabled(true)
                .build();
        Fresco.initialize(context, config);
        isInit = true;
    }
}

你可能感兴趣的:(android,java)