android - 使用 Glide 将图像加载到 ImageView 中

标签 android imageview android-glide

我有一个应用程序,可以将图像从 api 加载到我的 RecyclerView 中的 imageView 中。

这是我的 ImageView :

<ImageView
android:id="@+id/Group_ImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:layout_alignParentTop="true"
android:background="@color/_Opacity"
android:scaleType="centerInside"
android:src="@mipmap/ic_launcher" />

这是我的适配器中使用 glide 加载图像的部分:

Glide.with(mContext).load(goodGroups.getImageUrl()).asBitmap().dontTransform().listener(new RequestListener<String, Bitmap>() {
        @Override
        public boolean onException(Exception e, String s, Target<Bitmap> target, boolean b) {
            return false;
        }

        @Override
        public boolean onResourceReady(Bitmap bitmap, String s, Target<Bitmap> target, boolean b, boolean b1) {
            bitmap.setDensity(mContext.getResources().getDisplayMetrics().densityDpi);
            return false;
        }
    }).placeholder(R.mipmap.ic_launcher).error(R.drawable.ic_menu_gallery).into(holder.imageView);

下面是我的问题的屏幕截图: issue screen shot

我的问题出在图中红线所示的部分。蓝线显示我的 ImageView 。红色部分不应该显示。 我尝试将 ScaleType 更改为“FitXY”或“CenterCrop”,但它会扰乱图片尺寸。我希望在不进行任何裁剪的情况下显示图片,并保持其原始大小,并且在 ImageView 中没有这些类似填充的空间。

我该怎么办?!

最佳答案

在代码中为您的 ImageView 设置 android:adjustViewBounds="true"

关于android - 使用 Glide 将图像加载到 ImageView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45073937/

相关文章:

java.io.ioException : read failed, 套接字可能关闭或超时 Java Android Studio

android - 设置适配器后修改一个ListView

android - RecyclerView 滚动时改变高度如何解决?

android - 无法设置 GlideBuilder

android - 使用较新版本的 Glide Library(4.7.1) 导致绑定(bind)错误问题

android - 如何为启动画面设计图像?

android - Google 的 Firebase 下游消息的 http post 请求的 `Authorization` 部分是什么?

android - 如何从 Recycler View 中拖放图像并将其放置到另一个布局中

java - Java 中的泛型类参数

Android 在带有 mask 的部分 imageView 上应用 colorMatrix colorFilter