2013-04-30 100 views
0

我使用类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);  
      } 
      }); 
     } 
+0

mayb e你的布局高度不够 – 2013-05-01 03:34:17

+0

@MoshErsan哪种布局? imageview本身或它的父母? – user6827 2013-05-01 09:27:33

+0

我的意思是它的父母 – 2013-05-01 09:36:02

回答

0

这应该给你的图像的原始尺寸:

image.getDrawable().getIntrinsicHeight() 
image.getDrawable().getIntrinsicWidth() 
+0

'orgWidth'和'orgHeight'现在变为-1 – user6827 2013-05-01 09:28:23

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> 
+0

好了,现在高度只有它的一半,宽度是正确的。 – user6827 2013-05-01 12:21:53

+0

好的,更改'android:scaleType =“fitXy”' – 2013-05-01 13:01:04

+0

仍然是高度的一半,图片看起来现在已经被压扁了 – user6827 2013-05-01 13:13:43