ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android Picasso“fit().centerCrop()”不加载图片

2019-08-23 19:23:36  阅读:141  来源: 互联网

标签:android picasso android-imageview


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

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>

我尝试了将ImageView的宽度和高度设置为wrap_content和match_parent,但它也没有用.我在哪里错过了?提前致谢.

解决方法:

adjustViewBounds可以解决问题:

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

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

标签:android,picasso,android-imageview
来源: https://codeday.me/bug/20190823/1700344.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有