android - Android图像拉伸问题
问题描述
我有一个RecyclerView
使用它作为网格。在每个视图中,我都从 URL 加载图像。我尝试了 Picasso、Fresco 和 Glide。我对所有这些库只有一个问题,那就是图像被拉伸了。这是因为图像的大小不同。我正在提供我的SimpleDraweeView
.
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sdvRestaurant"
android:layout_width="match_parent"
android:layout_height="@dimen/_120sdp"
app:actualImageResource="@drawable/bg_city"
app:actualImageScaleType="fitXY"
android:adjustViewBounds="true"
android:background="@color/card_shadow_2"/>
我的问题是,避免这种图像拉伸问题的正确方法是什么?我认为不可能更改图像的大小。我尝试过的比例类型fitXY
没有帮助。此外,centerCrop
属性裁剪我的原始图像。请给出一些提示来解决这个问题。提前致谢。
解决方案
您正在为图像使用固定高度,这会导致图像被拉伸到该大小。我想当你在网格中显示它们时,你有必要拥有每个图像的固定大小。但是,您可以将布局的整体容器设置为具有固定高度,而您可能将图像高度设置为wrap_content
. 以下是您可能会考虑尝试的方法。
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sdvRestaurant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:background="@color/card_shadow_2"
android:src="@drawable/bg_city" />
请检查我是否已将 设置layout_height
为wrap_content
并将 设置scaleType
为fitCenter
。希望有帮助!