我正在尝试在列表视图的每一行中创建图像的横向视图。我正在使用毕加索来获取图像。我的问题是,在滚动时,horizontalscrollview中的图像会混乱。我希望使用:into(android.widget.ImageView目标,Callback回调)方法可以帮助imageview同步,但没有。
代码:
公共类RParrayAdapter扩展了ArrayAdapter {
static class ViewHolder {
ImageView photoThumbIv1;
ImageView photoThumbIv2;
int position;
}
private final Context context2;
int mWidth;
int mHeight;
Callback callback;
ViewHolder viewHolder;
public RParrayAdapter(Context context2, ArrayList<Listing2> listings2) {
super(context2, R.layout.list_item, listings2);
this.context2 = context2;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Listing2 listing2 = getItem(position);
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.list_item, null);
viewHolder.photoThumbIv1 = (ImageView) convertView
.findViewById(R.id.photo_thumb_1);
viewHolder.photoThumbIv2 = (ImageView) convertView
.findViewById(R.id.photo_thumb_2);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
DisplayMetrics metrics = new DisplayMetrics();
metrics = getContext().getResources().getDisplayMetrics();
mWidth = (int) (.9 * (metrics.widthPixels));
mHeight = (int) (mWidth / 1.33);
if (listing2.thumbnail_image_url1 != null) {
Picasso.with(context2).load(listing2.thumbnail_image_url1)
.resize(mWidth, mHeight).centerCrop()
.into(viewHolder.photoThumbIv1, new Callback() {
@Override
public void onSuccess() {
viewHolder.photoThumbIv2
.setVisibility(View.VISIBLE);
}
@Override
public void onError() {
}
});
}
if (listing2.thumbnail_image_url2 != null) {
Picasso.with(context2).load(listing2.thumbnail_image_url2)
.resize(mWidth, mHeight).centerCrop()
.into(viewHolder.photoThumbIv2, new Callback() {
@Override
public void onSuccess() {
viewHolder.photoThumbIv2
.setVisibility(View.VISIBLE);
}
@Override
public void onError() {
}
});
}
Picasso.with(context2).toString();
}
return convertView;
}
}
感谢您的帮助。
答案 0 :(得分:0)
在我们提出其他怀疑之前。不应该是第一个if
if (listing2.thumbnail_image_url1 != null) {
Picasso.with(context2).load(listing2.thumbnail_image_url1)
.resize(mWidth, mHeight).centerCrop()
.into(viewHolder.photoThumbIv1, new Callback() {
@Override
public void onSuccess() {
viewHolder.photoThumbIv1
.setVisibility(View.VISIBLE);
}
@Override
public void onError() {
}
});
}
viewHolder.photoThumbIv2.setVisibility(View.VISIBLE);
可能是viewHolder.photoThumbIv1.setVisibility(View.VISIBLE);
,因为您要将图片加载到viewHolder.photoThumbIv1