我正在使用Picasso库将图像加载到ImageView中,就像我在ListView中只有一个项目一样,因此它显示进度加载器甚至图像已成功下载并在ImageView中可见。
那我怎么能控制它?
viewHolder.progressBar.setVisibility(View.VISIBLE);
Picasso.with(MainActivity.this)
.load(imageURL) // web image URL
.fit().centerInside()
.transform(transformation)
.error(R.drawable.ic_launcher)
.placeholder(R.drawable.ic_launcher)
.rotate(90)
.into(viewHolder.imageViewReport , new Callback() {
@Override
public void onSuccess() {
// TODO Auto-generated method stub
viewHolder.progressBar.setVisibility(View.GONE);
}
@Override
public void onError() {
// TODO Auto-generated method stub
viewHolder.progressBar.setVisibility(View.GONE);
}
});
通常,我面临第一个列表项的问题......
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// convert view = design
View view = convertView;
if (view == null) {
viewHolder = new ViewHolder();
view = layoutInflater.inflate(Resource, null);
viewHolder.imageView = (ImageView) view.findViewById(R.id.imageView);
viewHolder.progressBar = (ProgressBar) view.findViewById(R.id.progressBar1);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
final Transformation transformation = new Transformation() {
@Override
public Bitmap transform(Bitmap source) {
int targetWidth = viewHolder.imageViewReport.getWidth();
double aspectRatio = (double) source.getHeight() / (double) source.getWidth();
int targetHeight = (int) (targetWidth * aspectRatio);
Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
if (result != source) {
// Same bitmap is returned if sizes are the same
source.recycle();
}
return result;
}
@Override
public String key() {
// TODO Auto-generated method stub
return null;
}
};