在项目中做瀑布流的时候,想让图片根据屏幕比例缩放,最后没有使用,但是还是简单记录一下方法
通过Glide我们可以在资源准备好之后,获取图片宽高
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;
}
});
另外,如果不用Glide的话,还有一种思路,我们可以通过BitmapFactory的Options来获取图片的宽高。