Android图像拉伸问题



我有一个RecyclerView将其用作网格。在每个视图中,我都从URL加载一个图像。我试过毕加索、弗雷斯科和格莱德。我对所有这些库只有一个问题,那就是图像被拉伸了。这是因为图像的大小不同。我正在提供我的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。希望能有所帮助!

最新更新