2016-12-19 4 views
0

私はサービスからイメージをロードするためにPicassoライブラリを使用しています。そのうまく動作します。しかし、scrollの画像が下にスクロールアップされている間に、画像はのレイアウトでrecyclerviewを使用して伸ばされました。イメージピカソを使用して伸ばした

私のアダプタクラスで
<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="3dp"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
<LinearLayout 
    android:id="@+id/bg_image_layout" 
    android:layout_width="match_parent" 
    android:layout_height="175dp" 
    android:orientation="vertical"> 
     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/bg_image" 
      android:layout_gravity="center" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:src="@mipmap/ic_launcher"   /> 

    </LinearLayout> 
     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:layout_gravity="center" 
      android:id="@+id/img_logo" 
      android:src="@drawable/logo" 
      android:layout_below="@id/bg_image_layout"/> 

    </RelativeLayout> 
</android.support.v7.widget.CardView> 

Picasso.with(context) 
        .load(items.get(position).getBgImage()) 
        .placeholder(R.mipmap.ic_launcher) 
        .fit() 
        .centerCrop() 
        .into(shopViewHolder.bgImage); 

いずれかが私を助けることができることができます..私はここで間違っていたところ...

答えて

1

あなたは.fit()を使用?。それはあなたのshopViewHolder.bgImage(必要に応じてストレッチ)にイメージを収めるでしょう。画像は常に.resize(width, height)で特定のサイズのままにすることができます。次に、.centerCrop().centerInside()を使用して、オーバーラップの処理方法を制御できます。

異なるタイプの結果を希望する場合は、別の方法を使用する必要があります。

+0

画像を伸ばすことなく表示する必要があるので、この問題を解決するために使用する必要がありますか? – user

+0

'.fit()'と '.centerCrop()'を削除して '。 centerInside() ' '.resize(int、int)'も設定できます。私はテストしていませんが、それはあなたが必要とすることを行う必要があります。アスペクト比の維持に関する詳細はこちら:https://github.com/square/picasso/issues/226 – Knossos

+0

スクロールすると、画像ビューのスケールタイプのみが使用されます。 – user

関連する問題