【问题标题】:Image appears stretched after loading Placeholder image via Glide?通过 Glide 加载占位符图像后图像出现拉伸?
【发布时间】:2016-02-11 12:59:28
【问题描述】:

我正在尝试使用 Glide 在 Listview 中加载一些图像。如果我在加载图像时不使用占位符,则图像会正确加载。但是,当我尝试设置占位符时,我通过网络加载的图像会出现拉伸。这只发生在使用占位符图像的情况下。如果我要离开屏幕并返回(以便不加载占位符图像),图像就会正确显示。

这是我的简单 Glide 实现:

Glide.with(context)
                .load(url)
                .placeholder(R.drawable.empty_logo)
                .error(R.drawable.error)
                .into(imageView);

【问题讨论】:

  • 还将 CenterCrop 添加到您的 Glide 实现中

标签: android android-glide


【解决方案1】:

我知道我回答得很晚,但这就是它对我的帮助:

Glide.with(context).load(url).placeholder(R.drawable.empty_logo).dontAnimate().into(imageView);

使用 dontAnimate(),它对我有用。希望它有所帮助:)

【讨论】:

  • 它对我有用。但占位符图像位置正在发生变化。
【解决方案2】:

我遇到了同样的问题,如果占位符小于要获取的图像,则图像在加载到 ImageView 时会被拉伸。我尝试了我能想到的一切,以下对我来说非常有效:

我在 ImageView 上设置了以下属性:

<ImageView
    android:id="@+id/my_image_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"/>

并以如下方式使用Glide:

Glide.with(myImageView.getContext())
            .load(imageUrl)
            .placeholder(R.drawable.placeholder)
            .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
            .into(myImageView);

这里要注意的关键是 ImageView 上的 adjustViewBounds 属性设置为 true,最重要的是 .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) - 这个将强制 Glide 使用图像的原始大小。

您也可以在 .override() 中以像素为单位指定大小,但请确保为您的 ImageView 指定正确的 ScaleType,否则它也会拉伸图像。

【讨论】:

    【解决方案3】:

    我想,您已经将 Imageview 的宽度和高度都指定为 Wrap_content。 因此,每当 Glide 加载图像时,一些图像的尺寸可能会更大,因此会被拉伸。

    试试这个。

    <ImageView
    android:width="match_parent"
    android:height="50dp"
    android:scaleType="fitXY"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 2017-06-11
      相关资源
      最近更新 更多