2016-01-12 27 views
-1

我需要創建一個包含圖像列表的片段。創建圖像列表的最佳方法

我做了以下內容:

  • RecyclerView;
  • CardView與ImageView;
  • RecyclerView適配器;

我有一個URL創建一個適配器的列表。在適配器的onBindViewHolder我使用畢加索爲了加載圖像到ImageView。

這種方法的工作原理,但我不知道它是最好的。圖像並不總是有正確的尺寸,我有一個隨機的錯誤,如圖像出現和消失在滾動。

你有什麼建議?

編輯:

XML佈局:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:id="@+id/card_view" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_margin="15dp" 
card_view:cardCornerRadius="4dp"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="fitCenter" 
    android:id="@+id/thumbnail"/> 
</android.support.v7.widget.CardView> 
+0

我沒有看到你的方法有什麼問題,圖像尺寸是由於你的cardview佈局(XML文件)。 你也遇到了什麼樣的錯誤,請給出更多細節? – Boukharist

+0

@Boukharist手錶我的編輯請。 – helloimyourmind

+0

請嘗試android:scaleType =「fitXY」。 如果你想加載它試試這個代碼 '畢加索 。隨着(上下文) .load(鏈接) .resize(6000,2000) .into(imageViewResize)之前縮放圖像;' 在這裏看到更多信息:[picasso image resizing](https://futurestud.io/blog/picasso-image- resizing-scaling-andfit) – Boukharist

回答

0

我用下面的方法,它很適合我。

的圖像並不總是有合適的尺寸

ImageView

<ImageView 
      android:id="@+id/image_college_news" 
      android:layout_width="@dimen/dimen_90" 
      android:layout_height="@dimen/dimen_90" 
      android:scaleType="centerCrop" 
      android:src="@drawable/ic_default_image" /> 

,並顯示使用Universal Image Loader以下設置的圖像:

DisplayImageOptions options = new DisplayImageOptions.Builder() 
      .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) 
      .cacheInMemory(true) 
      .cacheOnDisk(true) 
      .considerExifParams(true) 
      .build(); 

希望它有助於。