【问题标题】:maintaing aspect ratio of image when loading image using picasso?使用毕加索加载图像时保持图像的纵横比?
【发布时间】:2016-06-01 21:55:47
【问题描述】:

我正在使用毕加索加载图像。我想调整图像大小以保持纵横比。到目前为止,我发现当我使用 fit() 方法时。它将调整图像大小并填充图像视图(将显示完整图像但不保持纵横比),如果我使用 centercrop() 它将裁剪图像的中心部分以满足图像视图大小(但在这种情况下,纵横比比例保持不变)。我希望两者都发生。在我的 XML 中,图像视图的高度是 200dp

Picasso.with(mcontext).setIndicatorsEnabled(true);
            Picasso.with(mcontext).load("http://192.168.0.14:1337/show_all_offers/" + current.offercover).fit().centerCrop()
                    .networkPolicy(NetworkPolicy.OFFLINE)
                    .into(holder.offercover, new com.squareup.picasso.Callback() {
                        @Override
                        public void onSuccess() {
                            Log.d("cover", "success");
                        }

                        @Override
                        public void onError() {
                            Log.d("cover", "failure");
                        }
                    });

【问题讨论】:

    标签: android imageview picasso


    【解决方案1】:

    我使用下面的代码来保持纵横比。图像将从侧面被切掉。

    Picasso.with(ctx).load(imageURL).fit().centerCrop().placeholder(R.mipmap.fallback_image).error(R.mipmap.fallback_image).into(imageView);
    

    这可能会对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-11
      • 1970-01-01
      • 2016-12-20
      • 2016-02-05
      • 2019-09-03
      相关资源
      最近更新 更多