作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试逐步加载大尺寸 JPG。我看到了this documentation使用 Fresco,这正是我想要的:模糊延迟加载效果。我从 repo sample 中获取了他们的代码看起来像这样包装:
ImageFormatProgressiveJpegFragment.java
private void setImageUri(Uri uri) {
mDebugOutput.setText("");
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
.setProgressiveRenderingEnabled(mProgressiveRenderingEnabled)
.build();
DraweeController controller =
Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setRetainImageOnFailure(true)
.setPerfDataListener(mImagePerfDataListener)
.setControllerListener(
new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(
String id,
@javax.annotation.Nullable ImageInfo imageInfo,
@javax.annotation.Nullable Animatable animatable) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, true);
}
}
@Override
public void onIntermediateImageSet(
String id, @javax.annotation.Nullable ImageInfo imageInfo) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, false);
}
}
@Override
public void onIntermediateImageFailed(String id, Throwable throwable) {
mDebugOutput.append(
String.format(
Locale.getDefault(),
"onIntermediateImageFailed, %s\n",
throwable.getMessage()));
}
})
.build();
mSimpleDraweeView.setController(controller);
}
private void logScan(QualityInfo qualityInfo, boolean isFinalImage) {
mDebugOutput.append(
String.format(
Locale.getDefault(),
"%s: %s, goodEnough=%b, fullQuality=%b, quality=%d\n\n",
mDateFormat.format(new Date(System.currentTimeMillis())),
isFinalImage ? "final" : "intermediate",
qualityInfo.isOfGoodEnoughQuality(),
qualityInfo.isOfFullQuality(),
qualityInfo.getQuality()));
}
result是加载时图像信息的输出。
除了部分替换日志外,我的代码看起来是一样的:
MyFrescoActivity.java
private String IMAGE_URL = "https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73726/world.topo.bathy.200406.3x5400x2700.png";
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(IMAGE_URL))
.setProgressiveRenderingEnabled(true)
.build();
DraweeController controller =
Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setRetainImageOnFailure(true)
.setPerfDataListener(this)
.setControllerListener(
new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(
String id,
@Nullable ImageInfo imageInfo,
@Nullable Animatable animatable) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, true);
}
}
@Override
public void onIntermediateImageSet(
String id, @Nullable ImageInfo imageInfo) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, false);
}
}
@Override
public void onIntermediateImageFailed(String id, Throwable throwable) {
Log.i("DraweeUpdate",
String.format(
Locale.getDefault(),
"onIntermediateImageFailed, %s\n",
throwable.getMessage()));
}
})
.build();
simpleDraweeView.setController(controller);
}
private void logScan(QualityInfo qualityInfo, boolean isFinalImage) {
Log.i("DraweeUpdate", String.format(
Locale.getDefault(),
"%s: %s, goodEnough=%b, fullQuality=%b, quality=%d\n\n",
"",
isFinalImage ? "final" : "intermediate",
qualityInfo.isOfGoodEnoughQuality(),
qualityInfo.isOfFullQuality(),
qualityInfo.getQuality()));
}
仍然,我没有在 onIntermediateImageSet
上收到响应。当图像完全加载时,此监听器上唯一被调用的是 onFinalImageSet
。任何人都知道发生了什么事?
最佳答案
您可以尝试将模拟器和网络类型设置为 GPRS 进行测试
关于android - Fresco - 来自 ControllerListener 的 onIntermediateImageSet 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57184627/
我正在尝试逐步加载大尺寸 JPG。我看到了this documentation使用 Fresco,这正是我想要的:模糊延迟加载效果。我从 repo sample 中获取了他们的代码看起来像这样包装:
我是一名优秀的程序员,十分优秀!