gpt4 book ai didi

Android Picasso "fit().centerCrop()"不加载图像

转载 作者:太空宇宙 更新时间:2023-11-03 12:27:51 24 4
gpt4 key购买 nike

我想在我的 imageview 中显示图像 (URL) 作为最大宽度和可变高度根据宽度大小,当我使用此代码部分时:

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

Picasso.with(context).load(product.getImage()).fit().centerInside().into(imageView);

我的 imageview 什么都不显示。我不明白为什么。也许是我的列表设计和 ImageView 的问题。这是我的 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>

我尝试设置 wrap_contentma​​tch_parent ImageView 的宽度和高度,但它也没有用。我哪里不见了?提前致谢。

最佳答案

adjustViewBounds 可以解决这个问题:

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

我发现使用 XML 属性而不是 Picasso 方法更容易配置此行为。

关于Android Picasso "fit().centerCrop()"不加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43958397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com