2014-02-22 41 views
0

我正在使用Universal Image Downloader創建延遲加載列表視圖。到現在爲止,我已將height="200dp"設置爲我的ImageView,但我想知道如何才能使ImageViewheight對應於實際圖像height來自具有確切大小的網絡的Android顯示圖像

我試圖實現與Facebook9gag應用程序相同的行爲,即使圖像尚未加載,ImageView已經有了高度。

我猜他們與所輸入的數據一起發送的圖像尺寸(寬度和高度),並使用它們調整ImageView以前加載圖像,但是這只是一個猜測。

任何想法?

+0

可以複製? http://stackoverflow.com/questions/16909591/universal-image-loader-get-original-image-size – muetzenflo

+0

我不認爲這是我想要的。我想在**圖片加載前將尺寸設置爲我的ImageView **,**不** ** onLoadingComplete' –

回答

0

使用wrapcontent對於像 機器人imageview的:layout_height = WRAP_CONTENT 機器人:layout_width = WRAP_CONTENT

+0

不是我想要的。我希望'ImageView'的尺寸設置爲** BEFORE **圖像加載。 –

0

U可以使用烏爾目的此方法。方法是returnig Rect obj.from你可以得到圖像的高度寬度,你可以先將高度設置爲imageview,然後應用下載代碼。

private Rect getBitmapBounds(Uri uri) { 
    Rect bounds = new Rect(); 
    InputStream is = null; 

    try { 
     is = context.getContentResolver().openInputStream(uri); 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     BitmapFactory.decodeStream(is, null, options); 

     bounds.right = options.outWidth; 
     bounds.bottom = options.outHeight; 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } finally { 
     closeStream(is); 
    } 

    return bounds; 
} 

對於下載圖像此鏈接有一些方法以及.. Follow the link

+0

沒有幫助你這? – Manmohan

相關問題