2013-06-26 44 views
0

在我的代碼中,我想爲我的imageview設置一個默認圖像。我所有的圖片都是174px x 174px。所以,我想讓默認圖像的大小相同。這是我的圖像視圖圖像視圖不顯示在xml中定義的清晰圖像

//....code 

<ImageView 
    android:id="@+id/ivCover" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:contentDescription="Default Image" 
    android:src="@drawable/default_cover" /> 


//....some other code 

XML現在,我的default_cover.jpg也是174px X 174px。但它顯示了一個較小的圖像。我已經嘗試了所有

android:scaleType="centerInside" 
android:scaleType="center" 
android:scaleType="matrix" 

即使其中大多數是毫無意義的,我但我仍然嘗試了所有的「時間&他們沒有工作。然後,我通過指定

android:layout_width="174px" 
android:layout_height="174px" 

指定的高度&寬度圖像的(I知道使用dp爲比像素更好,但因爲這個圖象尺寸是固定的&我只是測試它)。因此它顯示

default image which doesn't look good同時使用

Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(url_source_for_image).getContent()); 
ivCover.setImageBitmap(bitmap); 

期望的圖像從外部URL加載時[默認圖像]

clear image with desired image quality []

兩個圖片可能無法看這裏非常不同,但是我的android設備上的區別非常明顯。請不要說我沒有嘗試其他的解決辦法.. 這裏是如此本身的鏈接列表..

ImageView fit without stretching the image

Fit image into ImageView, keep aspect ratio and then resize ImageView to image dimensions?

ImageView one dimension to fit free space and second evaluate to keep aspect ration

Resizing ImageView to fit to aspect ratio

Maximum width and height for ImageView in Android

Image in ImageView is stretched - Android

Android: How to prevent image from being scaled in ImageView or ImageButton?

+0

哪個可繪製的文件夾是你的位圖?如果您將drawable-ldpi中的50x50位圖和drawable-hdpi中的174x174位圖放入,Android將根據設備的分辨率決定要顯示哪一個,而不是您指定的大小。如果您想要在所有設備上顯示特定的位圖(不管分辨率如何),請將其放在res \ drawable-nodpi中。 – DevOfZot

+0

圖像在res \ drawable-xxhdpi中,因爲我認爲android智能縮放圖像大小以顯示低分辨率設備。 –

+0

正確,所以也許它會縮小圖像以降低分辨率,然後將其縮小到適合您指定的大小。如果你把它放在drawable-nodpi中,它會起作用嗎? – DevOfZot

回答

3

聽起來就像是答案是使用可繪製-nodpi。爲了將來的參考,如果您在ldpi/hdpi/etc和no-dpi中都有相同的命名圖像,我認爲no-dpi將被忽略。

相關問題