2013-04-30 8 views
0

我使用gridview,顯示圖像的2列列表。在gridview中的imageview錯誤的大小,更換加載佔位符後

我使用通用圖像加載程序從數據庫中獲取圖像,效果很好,但只要加載圖像,並且「加載圖像」佔位符被替換,圖像的大小就會縮小爲圖像的實際大小,並且不能正確填充單元格。

正確放大佔位符圖像以填充可用寬度幷包裹高度。 所有圖像尺寸相同,需要根據屏幕尺寸進行放大或縮小。

這裏是清單項目佈局(更新,我有一個TextView那裏,我認爲這是無關緊要的,但誰知道..):

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ImageView 
     android:id="@+id/grid_gallery_item_imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerInParent="true" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:src="@drawable/loading_image" /> 

    <TextView 
     android:id="@+id/grid_gallery_item_textView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/grid_gallery_item_imageView1" 
     android:background="#50000000" 
     android:ellipsize="end" 
     android:gravity="center_vertical" 
     android:maxLines="3" 
     android:padding="8dp" 
     android:text="Bacon ipsum." 
     android:textColor="#ffffff" 
     android:textSize="20sp" /> 

</RelativeLayout> 

這裏是我的GridView:

<GridView 
     android:id="@+id/grid_gallery_layout_gridView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:numColumns="2" 
     android:stretchMode="columnWidth"> 

在我的GridView的適配器,我只是用這個加載圖片:

imageLoader.displayImage("db://" + item.imageId, holder.imageView, options); 

的選項:

options = new DisplayImageOptions.Builder().bitmapConfig(Bitmap.Config.RGB_565).showStubImage(R.drawable.loading_image) 
     .displayer(new FadeInBitmapDisplayer(Constants.GRIDVIEW_IMAGE_FADEIN_TIME)).build(); 

這裏是一個屏幕截圖,該問題的:

enter image description here

的加載的圖像應該是相同的大小,佔位符的圖像。

任何想法,爲什麼加載圖像可能會搞砸imageviews的大小?

編輯:向下縮放實際上工作正常,它的縮放是搞砸了。例如,在較小的屏幕上,圖像大小正確。

回答

2

看來我已經解決了這個問題。 如果在GridView中,ImageView不會正確放大圖像。

此代碼適用於我完美:link

1

我敢打賭,你需要

android:scaleType="centerCrop" 

而且沒有必要把單一的ImageView中的RelativeLayout

<ImageView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/grid_gallery_item_imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_centerInParent="true" 
    android:adjustViewBounds="true" 
    android:scaleType="centerCrop" 
    android:src="@drawable/loading_image" /> 

^如果你正確地改寫適配器,例如,你不需要id屬性

if (convertView == null) { 
    convertView = inflater.inflate(id, null); 
} 
imageView = (ImageView) convertView; 
+0

我不想裁剪圖像。在imageview旁邊還有一個textview,這與問題無關,所以我沒有包含它.. – Tamas 2013-04-30 08:01:27

+0

啊,明白了。確保高度,如果「加載」圖像的高度與想要的目標圖像一樣高。 – 2013-04-30 08:03:26

+0

所有圖像的大小相同(加載佔位符,實際圖像)。 – Tamas 2013-04-30 08:05:08