ImageLoader没有给出正确的尺寸
问题描述:
我使用类ImageLoader
从互联网上加载图像,但是当我想要获得宽度和高度的照片,它给我的宽度:1和高度:1。该ImageLoader的是ImageLoader的从这里:ImageLoaderImageLoader没有给出正确的尺寸
调用方法和计算方面:
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);
}
});
}
答
这应该给你的图像的原始尺寸:
image.getDrawable().getIntrinsicHeight()
image.getDrawable().getIntrinsicWidth()
+0
'orgWidth'和'orgHeight'现在变为-1 – user6827 2013-05-01 09:28:23
答
您可以抬高这个布局,并获得参考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>
mayb e你的布局高度不够 – 2013-05-01 03:34:17
@MoshErsan哪种布局? imageview本身或它的父母? – user6827 2013-05-01 09:27:33
我的意思是它的父母 – 2013-05-01 09:36:02