如何设置图像适合每个具有纵横比的屏幕

How to set image fit on every screen with aspect ratio

我有一些图像,来自服务器,我对图像分辨率感到困惑。如何以纵横比在每个屏幕上完整显示每个图像。

我需要不裁剪地覆盖整个屏幕。图像在每个分辨率屏幕上都应该是完整的。

   <ImageView
    android:id="@+id/photo_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"/>

图片来自服务器

Picasso.with(context).load(shopDataForAdvs.get(position).getSrc()).fit().placeholder(R.drawable.product_image).error(R.drawable.product_image).into(imageView);

这里我有一张图片正在播放

决定将我的评论升级为答案...

每张图片都有宽高比。每个 phone 都有纵横比。无法保证这两个宽高比相同,因此您有以下三种选择:

1 - 拉伸图像以适应。这就是 android:scaleType="fitXY" 和 Picasso fit() 调用正在做的事情。我真的不推荐这个选择,因为图像看起来 "weird",但它是一个有效的选择。

2 - 裁剪图像以适合。这将是 android:scaleType="centerCrop" 和毕加索 centerCrop()。这将放大图像(不拉伸它)直到图像的最小尺寸与 phone 的尺寸相匹配,并在另一个尺寸裁剪图像。

3 - 信箱。这将是 android:scaleType="centerInside" 或毕加索 centerInside()。这将放大图像(不拉伸它)直到图像的最大尺寸与 phone 的尺寸匹配,并将 ImageView 的其余部分留空。

我推荐选项 2,或者可能是选项 3 和 2 的组合(加载图像时不裁剪,但如果用户愿意,可以放大)。