2

I have an app which loads images from api into my imageView which is in my RecyclerView.

Here is my 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.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 : issue screen shot

my problem is with the part shown by a red line in the picture. the blue line shows my 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 its original size, and without these padding-like spaces in ImageView.

What should I do?!

Ramesh R
  • 7,009
  • 4
  • 25
  • 38
S.Aslpour
  • 86
  • 1
  • 1
  • 10
  • @color/opacity code and image url pls give to me – Bhuvaneshwaran Vellingiri Jul 13 '17 at 07:33
  • @BhuvaneshwaranVellingiri I've checked the image, and there is no problem with it, the picture has no padding or empty space with it. The gray part is my ImageView's background which the @color/opacity. I've changed it like this so it can be shown easily to you. – S.Aslpour Jul 13 '17 at 07:42

3 Answers3

2

Try this set Image url.

 Glide.with(getBaseContext())
.load("Your image url parse this place")
                .thumbnail(0.1f)
                .into(img_glide);
Ramesh R
  • 7,009
  • 4
  • 25
  • 38
2

set android:adjustViewBounds="true" for your ImageView in the code

PradyumanDixit
  • 2,372
  • 2
  • 12
  • 20
  • It worked...but when the picture isn't found and error placeholder is shown, ImageView's height is as much as it's width(so it's too big), what should I do for that?! – S.Aslpour Jul 13 '17 at 08:10
  • never mind :D ... I just removed the placeholders, Thanks. – S.Aslpour Jul 13 '17 at 08:18
  • In this case, please progress by callback. If it's failed, just load placeholder by load(R.drawable.) or something like that. dont use .placeholder – Nguyễn Gia Lễ Jul 14 '17 at 04:38
0

try following you have to user centerCrop or fitCenter methods.

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);
Mehul Kabaria
  • 6,404
  • 4
  • 25
  • 50
  • I've tried it ... but it stretches the image height – S.Aslpour Jul 13 '17 at 07:37
  • now there are empty spaces on the sides (left and right) and my picture's height is the ImageView's min_height – S.Aslpour Jul 13 '17 at 07:48
  • now I've tried centerCrop method like you said, and now the picture is cropped with the min_height (I want the picture shown fully not cropped) but the width of the picture is fit to the image view like it should @Mehul – S.Aslpour Jul 13 '17 at 07:58