【发布时间】:2020-06-24 19:26:24
【问题描述】:
我正在尝试将 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 之前更改获得的位图,例如更改宽度和高度,但基于原始尺寸。
【问题讨论】:
-
您在 logcat 中获得的任何日志?