【问题标题】:Picasso - how to resize placeholderPicasso - 如何调整占位符的大小
【发布时间】:2023-12-02 06:26:01
【问题描述】:

我正在使用 128x128 的圆形图像,由可绘制动画作为毕加索中的占位符。

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/loading_circle"
    android:pivotX="50%"
    android:pivotY="50%" />

这就是我的 Java 代码实现它的方式:

Picasso.with(context)
                        .load(message.getMediaUrl())
                        .config(Bitmap.Config.ARGB_4444)
                        .resize(w, h)
                        .onlyScaleDown()
                        .centerCrop()
                        .placeholder(R.drawable.progresscircle)
                        .into(messageImage);

请注意,加载到我的聊天适配器的图像视图中的最终图像需要上述图像大小参数。

问题是,毕加索正在炸毁并像这样裁剪占位符:

如何为占位符设置单独的参数以使其大小合适?另外,哪些具体参数会有帮助?

【问题讨论】:

  • 您找到解决方案了吗?

标签: android imageview android-drawable scaling picasso


【解决方案1】:

在您设置ImageViewXML 中添加。

android:scaleType="centerCrop"

它可能会起作用。如果它不起作用,您可以设置fitXY 而不是centerCrop

【讨论】:

    【解决方案2】:

    here所述,

    1. 在您的imageviews xml 集内android:scaleType="centerInside"

    2. 然后像这样添加fit().centerCrop().noFade()

                       Picasso.with(context)
                      .load(message.getMediaUrl())
                      .config(Bitmap.Config.ARGB_4444)
                      .resize(w, h)
                      .onlyScaleDown()
                      .centerCrop()
                      .fit()
                      .noFade()
                      .placeholder(R.drawable.progresscircle)
                      .into(messageImage);
      

    【讨论】:

      【解决方案3】:

      试试这个:

       Picasso
      .with(context)
      .load(message.getMediaUrl())
      .fit()
      // call .centerInside() or .centerCrop() to avoid a stretched image
      .into(messageImage);
      

      【讨论】:

        【解决方案4】:

        把你的毕加索电话改成这个,

        Picasso.with(context)
                            .load(message.getMediaUrl())
                            .config(Bitmap.Config.ARGB_4444)
                            .fit()
                            .centerCrop()
                            .placeholder(R.drawable.progresscircle)
                            .into(messageImage);
        

        【讨论】:

          最近更新 更多