Android obtains network image size through Glide

When doing waterfall flow in the project, I wanted to make the picture scale according to the screen ratio, but I didn’t use it in the end, but I still simply record the method

With Glide, we can get the picture width and height after the resource is ready

Glide.with(mContext).load(list.get(position).getImageUrl())
                    .error(R.drawable.home_banner_load_error)
                    .into(new SimpleTarget<Drawable>() {
    
    
                        @Override
                        public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
    
    
                            // 在这里可以获得图片的宽高
                            resource.getWidth;
                            resource.getHeight;
                        }
                    });

In addition, if you don't use Glide, there is another way of thinking. We can get the width and height of the picture through the Options of BitmapFactory.

Guess you like

Origin blog.csdn.net/A_Intelligence/article/details/111605942