0

我正在使用该类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);      
             }  
            });
        }
4

2 回答 2

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>
于 2013-05-01T11:45:02.540 回答
0

这应该为您提供图像的原始大小:

image.getDrawable().getIntrinsicHeight()
image.getDrawable().getIntrinsicWidth()
于 2013-05-01T03:09:35.830 回答