android - Glide 使 ImageView wrap_content 无用并且没有使用目标的动画

标签 android android-layout imageview android-glide

我在项目中使用Glide加载图片,但我发现了一个奇怪的事情。当我使用into(ImageView)时,ImageView显示与使用into(new BitmapImageViewTarget(centerImageView))时不一样:

这是我的布局:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <ImageView
        android:id="@+id/center_image_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

</RelativeLayout>

当我使用时:

String imageUrl = "http://7xlz1k.com1.z0.glb.clouddn.com/feedback-201604229711.png";
Glide.with(this).load(imageUrl).into(centerImageView);

ImageView 的wrap_content 不起作用,它显示如下: enter image description here

但是当我使用时:

    Glide.with(this).load(imageUrl).asBitmap().into(new BitmapImageViewTarget(centerImageView));

ImageView 看起来:

enter image description here

imageUrl中包含的图片是一张120*120的图片。

当我使用 BitmapImageViewTarget 时,默认动画不起作用。

三个问题:

  1. 为什么这两种方法有区别?

  2. 在使用第一种方法时,如何使 ImageView 的 wrap_content 有用?

  3. 以及如何在使用 BitmapImageViewTarget 时启用默认动画?

最佳答案

我将尝试为您的第二个问题提供解决方案:

  1. How can I make the ImageView's wrap_content useful when using the first method?

我设法通过将 adjustViewBounds 添加到 ImageView 的布局来使 wrap_content 工作:

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

关于android - Glide 使 ImageView wrap_content 无用并且没有使用目标的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36789526/

相关文章:

java - 在 Android 中创建自己的样式

Android Material Date Range Picker - 如何仅更改选定范围日期的文本颜色?

Android Studio 无线 ADB 错误 (10061)

android - 是否可以直接在 android 上录制 MJPEG?

Android的盒子模型

android - 内存不足加载 imageViews

android - 在下面的类中实现带屏幕限制的 Imageview 旋转

android - 如何以编程方式创建 ImageView 对象的多个副本?

android - 如何使用 Assets 作为 osmdroid 离线 map 的来源

android - Retrofit 2.0 的自定义类型适配器