默认情况下,我设置了一个66 x 66的小图片。当我想借助上面提到的URL更改它时,我无法设置大小为200 X 200的图像。它设置为仅66 X 66。
class DownloadImage extends AsyncTask<Void, Integer, Bitmap>{
ImageView imageView;
LinearLayout.LayoutParams lp;
public DownloadImage(ImageView iv){
imageView = iv;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
Animation anim = AnimationUtils.loadAnimation(cxt, R.anim.progress_anim);
anim.setFillAfter(true);
anim.setDuration(300);
imageView.startAnimation(anim);
}
@Override
protected void onProgressUpdate(Integer... values) {
// TODO Auto-generated method stub
imageView.clearAnimation();
imageView.requestLayout();
imageView.postInvalidate();
imageView.setImageBitmap(null);
imageView.setImageResource(0);
super.onProgressUpdate(values);
}
@Override
protected Bitmap doInBackground(Void... params) {
// TODO Auto-generated method stub
String url = (String) imageView.getTag();
try {
// Bitmap unscaledBitmap = ScalingUtilities.decodeResource(cxt.getResources(),R.drawable.photo,200, 200, ScalingUtilities.ScalingLogic.FIT);
Bitmap unscaledBitmap = ScalingUtilities.decodeStream(new URL(url),200, 200, ScalingUtilities.ScalingLogic.FIT);
Bitmap scaledBitmap = ScalingUtilities.createScaledBitmap(unscaledBitmap, 200, 200, ScalingUtilities.ScalingLogic.FIT);
unscaledBitmap.recycle();
if(scaledBitmap!=null)
publishProgress(1);
return scaledBitmap;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
@Override
protected void onPostExecute(final Bitmap result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if(result!=null){
imageView.setImageBitmap(result);
}
imageView.postInvalidate();
}
}
}
默认情况下,我设置了一个66 x 66的小图片。当我想借助上面提到的URL更改它时,我无法设置大小为200 X 200的图像。它设置为仅66 X 66。