我正在尝试在图像尚未加载时显示加载图标,并在图像准备好时隐藏加载图标。我正在使用Fresco库,我成功地使用了下面的代码来实现我想要的东西:
private void loadImage(ImageView imageview,final ImageView videoicon, final GifTextView progressbar, Uri uri,final boolean video,final boolean child,boolean isConnectivity)
{
if (child)
{
if (isConnectivity)
progressbar.setBackgroundResource(Theme.Icons.LoadingChild);
}
else
{
progressbar.setBackgroundResource(Theme.Icons.LoadingMain);
}
SimpleDraweeView imageDrawee = (SimpleDraweeView) imageview;
ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) {
if (imageInfo == null) {
return;
}
progressbar.setVisibility(View.GONE);
if (video)
{
if (child)
{
videoicon.setImageResource(Theme.Icons.MediaGalleryVideoIcon);
}
else
{
linearlayout_mediagalleryvideoicon.setVisibility(View.VISIBLE);
videoicon.setImageResource(Theme.Icons.MediaGalleryVideoIcon);
}
}
}
@Override
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
//FLog.d("Intermediate image received");
}
@Override
public void onFailure(String id, Throwable throwable) {
//FLog.e(getClass(), throwable, "Error loading %s", id)
}
};
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setControllerListener(controllerListener)
.setOldController(imageDrawee.getController())
.setUri(uri)
.build();
imageDrawee.setController(controller);
}
我的问题是,当我关闭Fragment时,我可以从Android监视器看到DraweeController继续使用CPU。当我打开包含一个图像的20-30片段时,我的应用程序因CPU负载过重而崩溃。
如何克服这个问题?
答案 0 :(得分:0)
问题不在于Fresco库,而是我用来显示GIF图像的库。