我希望将图片(URL)显示在我的ImageView中,使其宽度最大,高度根据宽度大小可变。当我使用以下代码时:
我可以将图片显示在ImageView中。我还尝试使用resize().centerCrop()方法,它也成功了。
但是,当我使用以下代码时:
imageView = (ImageView) convertView.findViewById(R.id.imageView);
Picasso.with(context).load(product.getImage()).into(imageView);
我可以将图片显示在ImageView中。我还尝试使用resize().centerCrop()方法,它也成功了。
但是,当我使用以下代码时:
或者Picasso.with(context).load(product.getImage()).fit().centerCrop().into(imageView);
我的ImageView没有显示出任何内容。我不明白为什么会这样,可能是我的列表设计和ImageView存在问题。这是我的list_content_item.xml:Picasso.with(context).load(product.getImage()).fit().centerInside().into(imageView);
<?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>
我尝试将ImageView的宽度和高度都设置为wrap_content和match_parent,但仍然没有起作用。我错在哪里?谢谢。
Picasso
的跟踪信息,可以通过Picasso.with(context).setLoggingEnabled(true);
实现。您可以将此行代码放入您的Application
中以记录整个应用程序,或者只需将其放入您的 Activity/Fragment 中即可。 - Cătălin Florescu