2013-04-30 3 views
0

J'utilise la classe ImageLoader pour charger une image sur internet, mais quand je veux obtenir la largeur et la hauteur de la photo, cela me donne la largeur: 1 et la hauteur: 1. Le ImageLoader est le ImageLoader d'ici: ImageLoaderImageLoader ne donne pas les bonnes dimensions

méthode d'appel et calculer les dimensions:

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 votre hauteur de mise en page ne suffit pas –

+0

@MoshErsan Quelle mise en page? L'imageview elle-même ou son parent? – user6827

+0

Je veux dire son parent –

Répondre

0

Cela devrait vous donner la taille originale de l'image:

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

'orgWidth' et' orgHeight' deviennent -1 maintenant – user6827

0

vous pouvez gonfler cette mise en page, et obtenir une référence à 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

bien, maintenant la hauteur est seulement la moitié de celui-ci, la largeur est correcte. – user6827

+0

ok, changer le 'android: scaleType =" fitXy "' –

+0

encore la moitié de la hauteur, l'image semble écrasée maintenant – user6827

Questions connexes