Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get width and height of an image from Glide

I have set <ImageView /> height to wrap_content. I am adding this layout in recycler adapter

There will be around 10 images all images are set to wrap_content.

Is there any way to get the height of image rendered by Glide.

I am using this, but its returning the screen dimensions and not image dimensions.

 Glide.with(context).load(imgpth).placeholder(R.drawable.bg_loading)
                            .error(R.drawable.bg_loading).into(imageProdctBanner).getSize(new SizeReadyCallback() {
                        @Override
                        public void onSizeReady(int width, int height) {
                            Log.e("width","wdthheight "+width+"  :  "+height);

                        }
                    });

I need this to set height of recyclerView.

int totalItems= cardsRecyclerAdapter.getItemCount();

    ViewGroup.LayoutParams params=rvCards.getLayoutParams();
    params.height= heightOfImageView *totalItems;
    rvCards.setLayoutParams(params);
like image 773
dev90 Avatar asked Dec 19 '18 16:12

dev90


1 Answers

use onResourceReady() method instead

Glide.with(getContext().getApplicationContext())
     .asBitmap()
     .load(path)
     .into(new SimpleTarget<Bitmap>() {
         @Override
         public void onResourceReady(Bitmap bitmap,
                                     Transition<? super Bitmap> transition) {
             int w = bitmap.getWidth();
             int h = bitmap.getHeight()
             mImageView.setImageBitmap(bitmap);
         }
     });
like image 124
touhid udoy Avatar answered Nov 10 '22 20:11

touhid udoy