【问题标题】:Android Image stretch issueAndroid图像拉伸问题
【发布时间】:2019-05-10 09:51:13
【问题描述】:

我有一个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 属性会裁剪我的原始图像。请给出一些提示来解决这个问题。提前致谢。

【问题讨论】:

    标签: android android-imageview picasso android-glide fresco


    【解决方案1】:

    您正在为图像使用固定高度,这会导致图像被拉伸到该尺寸。我想当你在网格中显示它们时,你有必要拥有每个图像的固定大小。但是,您可以将布局的整体容器设置为具有固定高度,而您可能将图像高度设置为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。希望有帮助!

    【讨论】:

    • 我对此有一个疑问。如果我们使用 wrap_content 那么这一行的高度与另一行的高度不同吗?
    • 我想我在回答中已经考虑到了这一点。您的列表项有父布局吗?将高度约束设置为可能是LinearLayoutRelativeLayout 的父布局。如果您有任何其他困惑,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多