Android Picasso "fit (). CenterCrop ()" does not load image
I want to display an image (URL) to my image as the max width and height of a variable according to the size of the width when I use this piece of code:
imageView = (ImageView) convertView.findViewById(R.id.imageView); Picasso.with(context).load(product.getImage()).into(imageView);
I can display my image in an image. I have also tried using resize () methods . CenterCrop () and it worked successfully.
But, however, when I use
Picasso.with (context) .load (product.getImage ()) fit () centerCrop () in (ImageView); ...
or
Picasso.with (context) .load (product.getImage ()) fit () centerInside () in (ImageView); ...
my image is displaying nothing. I do not understand why. Maybe the problem is in my list design and viewport. Here is my 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>
I tried setting wrap_content and match_parent to both the width and height of the ImageView, and it didn't work. Where am I missing? Thanks in advance.
source to share
First, you don't add .
before use fit()
. Change the code as follows:
Picasso.with(context).load(product.getImage()).fit().centerCrop().into(imageView
)
Alternatively, you can also define a scalar type for your image with android:scaleType="fitXY"
In the XML youn.
Then put the image back into an image: Picasso.with(context).load(product. getImage).fit().into(imageView);
source to share