我正在使用班级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);
}
});
}
答案 0 :(得分:0)
这应该为您提供图像的原始大小:
image.getDrawable().getIntrinsicHeight()
image.getDrawable().getIntrinsicWidth()
答案 1 :(得分:0)
您可以对此布局进行充气,并获得对ImageView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView android:id="@+id/my_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter" />
</LinearLayout>