我在项目中使用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
不起作用,它显示如下:
但是当我使用时:
Glide.with(this).load(imageUrl).asBitmap().into(new BitmapImageViewTarget(centerImageView));
ImageView 看起来:
imageUrl
中包含的图片是一张120*120的图片。
当我使用 BitmapImageViewTarget
时,默认动画不起作用。
三个问题:
为什么这两种方法有区别?
在使用第一种方法时,如何使 ImageView 的
wrap_content
有用?以及如何在使用
BitmapImageViewTarget
时启用默认动画?
最佳答案
我将尝试为您的第二个问题提供解决方案:
- 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/