3

我有一個ImageView,我創建程序,並加載到使用畢加索的圖像。 ImageView的高度和寬度設置爲WRAP_CONTENT。圖像非常大,所以我想使用畢加索的.fit().centerCrop()方法來節省內存。但是,當我添加方法時,圖像不顯示,我認爲它必須是因爲WRAP_CONTENT。這裏是我的代碼:Picasso .fit().centerCrop()不適用於WRAP_CONTENT

ImageView iv = new ImageView(getContext()); 
RelativeLayout.LayoutParams centerParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
iv.setLayoutParams(centerParams); 
Picasso.with(context)load(path).fit().centerCrop().into(iv); //if I remove .fit().centerCrop(), the images load just fine 

我能找到這個問題的唯一信息是this issue on GitHub它 - 而這個問題說,這是在V2.4關閉,有些人評論說,他們正在經歷它V2。 5。 (我使用的是2.5版一樣)

編輯:這是我使用的是什麼,現在,每Angela的建議:

ImageView iv = new ImageView(getContext()); 
RelativeLayout.LayoutParams centerParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(350)); 
centerParams.addRule(RelativeLayout.CENTER_HORIZONTAL); 
iv.setLayoutParams(centerParams); 
iv.setAdjustViewBounds(true);          
iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 
Picasso.with(getContext()).load(path).fit().into(iv); 

這些圖像現在顯示出來,但他們不結垢正確地說,縱橫比發生了某種變化。有關如何保留寬高比,同時仍然允許畢加索獲得.fit()的測量結果的任何想法?

回答

3

我也遇到過這個問題。這是我沒有...

  Picasso 
        .with(context) 
        .load(path) 
        .fit() 
        .into(iv); 

在XML文件中儘量包含scaleType,adjustViewBounds和layout_gravity 例如:

<ImageView 
       android:id="@+id/img_movie" 
       android:layout_width="match_parent" 
       android:layout_height="350dp" 
       android:scaleType="fitXY" 
       android:adjustViewBounds="true" 
       android:layout_gravity="center" 
       /> 

希望這有助於! :)

+0

謝謝! :)圖片現在加載,但我無法讓它們正確縮放,高寬比不斷變化 - 上面的更新代碼。 – weirdo16

+0

不適合我。 –

1

使用

Picasso.with(getContext()).load(path).fit().centerInside().into(iv); 

Picasso.with(getContext()).load(path).fit().centerCrop().into(iv); 
相關問題