我正在使用该类ImageLoader
从互联网加载图像,但是当我想获取照片的宽度和高度时,它给了我宽度:1 和高度:1。图像加载器是来自这里的图像加载器:ImageLoader
调用方法并计算维度:
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
imgLoader.DisplayImage(url, R.drawable.thumbnail_background, image);
// Change params
image.post(new Runnable() {
public void run() {
ImageView image = (ImageView)findViewById(R.id.photo);
LinearLayout layout = (LinearLayout)findViewById(R.id.scrollLayout);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int newWidth = size.x;
int orgWidth = image.getWidth();
int orgHeight = image.getHeight();
Toast toast = Toast.makeText(getApplicationContext(), Integer.toString(newWidth) + " - " + Integer.toString(orgWidth) + " - " + Integer.toString(orgHeight), Toast.LENGTH_LONG);
toast.show();
int newHeight = (int) Math.floor(newWidth / (orgWidth / orgHeight));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
newWidth, newHeight);
//image.setLayoutParams(params);
image.setScaleType(ImageView.ScaleType.FIT_XY);
layout.updateViewLayout(image, params);
}
});
}