简体   繁体   English

使用Glide将图像加载到ImageView中

[英]Loading Image into ImageView with Glide

I have an app which loads images from api into my imageView which is in my RecyclerView. 我有一个应用程序,可将图像从api加载到RecyclerView中的imageView中。

Here is my 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" />

and here is the image loading part in my adapter with glide : 这是我的适配器中带有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);

here is the screen shot of my problem below : 这是下面我的问题的屏幕截图: 问题屏幕截图

my problem is with the part shown by red line in the picture. 我的问题是图片中红线显示的部分。 the blue line shows my imageview. 蓝线显示我的imageview。 the red part isn't supposed to be shown. 红色部分不应该显示。 I've tried changing the ScaleType to "FitXY" or "CenterCrop" but it messes up with the picture size.I want my picture shown without any cropping, with it's original size and without these padding like spaces in ImageView. 我曾尝试将ScaleType更改为“ FitXY”或“ CenterCrop”,但它与图片大小混淆了。我希望显示的图片没有任何裁剪,原始大小并且没有这些填充(如ImageView中的空格)。

What should I do?! 我该怎么办?!

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

Try this set Image url. 试试这个设置的图像URL。

 Glide.with(getBaseContext())
.load("Your image url parse this place")
               .diskCacheStrategy(DiskCacheStrategy.ALL)
                .thumbnail(0.1f)
                .into(img_glide);

try following you have to user centerCrop or fitCenter methods. 请尝试遵循您必须使用的centerCropfitCenter方法。

Glide.with(context).load(url).centerCrop().placeholder(R.drawable.default_image).into(img);

or 要么

Glide.with(context).load(url).fitCenter().placeholder(R.drawable.default_image).into(img);

or 要么

Glide.with(getActivity().getApplicationContext())
                .load(url).fitCenter()
                .override(500, 758)
                .into(mMovieBackgroundImageView);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM