3

私はプログラムで作成したImageViewを持っており、Picassoを使用してイメージを読み込みます。 ImageViewの高さと幅はWRAP_CONTENTに設定されています。画像はかなり大きいので、メモリを節約するためにPicassoの.fit().centerCrop()メソッドを使用したいと思います。しかし、メソッドを追加すると、画像が表示されず、WRAP_CONTENTが原因であると考えられます。ここに私のコードは次のとおりです。私はこの上で見つけることができるPicasso .fit().WAAP_CONTENTで動作しないcenterCrop()

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。ここではアンジェラの提案ごとに、私が今使っているものです::

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); 

イメージが今現れ、彼らはスケーリングされていない

EDITを(私もV2.5を使用しています)適切に、アスペクト比は何とか変更されます。アスペクト比を維持する方法についてのアイデアは、ピカソが.fit()の測定値を得ることを許可していますか?

答えて

3

この問題も発生しました。ここでは、XMLファイルで

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

は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); 
関連する問題