毕加索没有将位图加载到带有目标的图像视图中
Picasso not loading bitmap into imageview with target
我正在尝试将 url 加载到 ImageView 中,但 Target 似乎并不像我发现的那样工作。下面是我的代码:
ImageView methodButton= (ImageView) View.inflate(context, R.layout.view_home_scroll_view_image, null);
setMethodPicture(sectionModel.getContent().get(0).getThumbnail(), methodButton);
methodsContainer.addView(methodButton);
和
private void setMethodPicture(final String methodPicture, final ImageView methodButton){
methodButton.setBackgroundColor(0x000000);
if (!StringUtils.isEmpty(methodPicture)) {
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
methodButton.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
@Override
public boolean equals(Object o) {
return methodPicture.equals(o);
}
@Override
public int hashCode() {
return methodPicture.hashCode();
}
};
Picasso.with(context).load(methodPicture).into(target);
}
}
这不会将图片加载到 imageView,但是当我这样做时,
ImageView methodButton= (ImageView) View.inflate(context, R.layout.view_home_scroll_view_image, null);
methodButton.setBackgroundColor(0x000000);
Picasso.with(context).load(sectionModel.getContent().get(0).getThumbnail()).into(methodButton);
methodsContainer.addView(methodButton);
它加载图片。
我想做第一个,这样我就可以在将它放入 ImageView 之前更改我获得的位图,例如更改宽度和高度,但要基于原始尺寸。
我发现了问题,Picasso 持有对目标的弱引用。可以在此处找到正确答案:onBitmapLoaded of Target object not called on first load
改用 Glide,它提供预定义的约束选项,您可以使用它添加
我正在尝试将 url 加载到 ImageView 中,但 Target 似乎并不像我发现的那样工作。下面是我的代码:
ImageView methodButton= (ImageView) View.inflate(context, R.layout.view_home_scroll_view_image, null);
setMethodPicture(sectionModel.getContent().get(0).getThumbnail(), methodButton);
methodsContainer.addView(methodButton);
和
private void setMethodPicture(final String methodPicture, final ImageView methodButton){
methodButton.setBackgroundColor(0x000000);
if (!StringUtils.isEmpty(methodPicture)) {
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
methodButton.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
@Override
public boolean equals(Object o) {
return methodPicture.equals(o);
}
@Override
public int hashCode() {
return methodPicture.hashCode();
}
};
Picasso.with(context).load(methodPicture).into(target);
}
}
这不会将图片加载到 imageView,但是当我这样做时,
ImageView methodButton= (ImageView) View.inflate(context, R.layout.view_home_scroll_view_image, null);
methodButton.setBackgroundColor(0x000000);
Picasso.with(context).load(sectionModel.getContent().get(0).getThumbnail()).into(methodButton);
methodsContainer.addView(methodButton);
它加载图片。 我想做第一个,这样我就可以在将它放入 ImageView 之前更改我获得的位图,例如更改宽度和高度,但要基于原始尺寸。
我发现了问题,Picasso 持有对目标的弱引用。可以在此处找到正确答案:onBitmapLoaded of Target object not called on first load
改用 Glide,它提供预定义的约束选项,您可以使用它添加