2017-05-13 8 views
2

Je souhaite afficher l'image (URL) dans mon image comme largeur maximale et hauteur variable en fonction de la largeur, lorsque j'utilise ce code:Android Picasso "fit(). CenterCrop()" ne charge pas l'image

imageView = (ImageView) convertView.findViewById(R.id.imageView); 
Picasso.with(context).load(product.getImage()).into(imageView); 

Je peux afficher mon image dans l'imageview. J'ai également essayé resize(). CenterCrop() méthodes et cela a fonctionné avec succès.

Mais cependant, quand j'utilise

Picasso.with (contexte) .load (product.getImage()) s'adapter() centerCrop() dans (imageView)...

ou

Picasso.with (contexte) .load (product.getImage()) ajuster() centerInside() en (en imageView)...;

mon imageview n'affiche rien. Je ne comprends pas pourquoi. Peut-être le problème ma conception de la liste et imageview. Voici mon list_content_item.xml:

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

    android:weightSum="1"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.80" 
     app:srcCompat="@mipmap/ic_launcher" /> 

    <LinearLayout 

     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1" 
     android:layout_weight="0.2" 
     android:orientation="horizontal"> 
     <TextView 
      android:id="@+id/tv_title" 
      android:layout_width="match_parent" 
      android:layout_weight="0.3" 
      android:layout_height="match_parent" /> 
     <TextView 
      android:id="@+id/tv_stats" 
      android:layout_weight="0.7" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center"/> 

    </LinearLayout> 

</LinearLayout> 

J'ai essayé mis wrap_content et match_parent à la fois de la largeur et de la hauteur ImageView et il n'a pas fonctionné, aussi. Où suis-je porté disparu? Merci d'avance.

+0

Utilisation connexion pour voir la trace de picasso en utilisant 'Picasso.with (contexte) .setLoggingEnabled (true);' Vous pouvez mettre cette ligne dans votre 'Application' pour vous connecter toute l'application ou juste dans votre activité/fragment. –

Répondre

3

adjustViewBounds fait le tour

 android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:adjustViewBounds="true" 
     android:scaleType="centerCrop" 

J'utilise picasso aussi, mais pour moi il vaut mieux ajouter des attributs XML ... Votre code est plus

+0

Merci cela a fonctionné. J'ai mis à jour mon imageview comme ceci et ai changé mon code comme ceci: ** Picasso.with (context) .load (product.getImage()). Dans (imageView); ** – pseudocode

0

Premièrement, vous n'ajoutez pas de . avant d'utiliser fit(). Remplacez votre code avec ceci: Picasso.with(context).load(product.getImage()).fit().centerCrop().into(imageView)

En tant alternative, vous pouvez également définir le scaleType à votre imageView en utilisant android:scaleType="fitXY" Dans le fichier xml youn.

ensuite obtenir votre image en imageview: Picasso.with(context).load(product. getImage).fit().into(imageView);

+0

J'ai essayé. Mais ça n'a pas marché. imageview ne montre plus rien. – pseudocode