public class FrescoUtils {
public static void setControllerListener(final SimpleDraweeView simpleDraweeView, String imagePath, final int imageWidth) {
final ViewGroup.LayoutParams layoutParams = simpleDraweeView.getLayoutParams();
ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) {
if (imageInfo == null) {
return;
}
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
layoutParams.width = imageWidth;
layoutParams.height = (int) ((float) (imageWidth * height) / (float) width);
simpleDraweeView.setLayoutParams(layoutParams);
}
@Override
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
Log.d("TAG", "Intermediate image received");
}
@Override
public void onFailure(String id, Throwable throwable) {
throwable.printStackTrace();
}
};
DraweeController controller = Fresco.newDraweeControllerBuilder().setControllerListener(controllerListener).setUri(Uri.parse(imagePath)).build();
simpleDraweeView.setController(controller);
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.widthPixels;
public static void setControllerListener(final SimpleDraweeView simpleDraweeView, String imagePath, final int imageWidth) {
final ViewGroup.LayoutParams layoutParams = simpleDraweeView.getLayoutParams();
ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) {
if (imageInfo == null) {
return;
}
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
layoutParams.width = imageWidth;
layoutParams.height = (int) ((float) (imageWidth * height) / (float) width);
simpleDraweeView.setLayoutParams(layoutParams);
}
@Override
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
Log.d("TAG", "Intermediate image received");
}
@Override
public void onFailure(String id, Throwable throwable) {
throwable.printStackTrace();
}
};
DraweeController controller = Fresco.newDraweeControllerBuilder().setControllerListener(controllerListener).setUri(Uri.parse(imagePath)).build();
simpleDraweeView.setController(controller);
}
----------------------------------------------------------
public class UIUtils {
public static int getScreenWidth(Context context) {WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.widthPixels;
}
----------------------------------------------------------
FrescoUtils.setControllerListener(holder.sv_img,split[0],UIUtils.getScreenWidth(context));