android - 如何从 Glide 获取图像的宽度和高度
问题描述
我已将<ImageView />
高度设置为wrap_content
. 我正在添加这个布局recycler adapter
将周围的10 images
所有图像都设置为wrap_content
。
有什么方法可以获取 Glide 渲染的图像的高度。
我正在使用它,但它返回屏幕尺寸而不是图像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);
}
});
我需要这个来设置recyclerView的高度。
int totalItems= cardsRecyclerAdapter.getItemCount();
ViewGroup.LayoutParams params=rvCards.getLayoutParams();
params.height= heightOfImageView *totalItems;
rvCards.setLayoutParams(params);
解决方案
改用onResourceReady()
方法
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);
}
});
推荐阅读
- php - PHP处理张贴数组
- swift - 类型转换是 Swift 中的原子操作吗?- BAD_ACCESS_ERROR
- python-3.x - 为什么 geckdriver(在 selenium,python 中)让谷歌认为我是一个机器人,但在普通的 firefox(具有相同的 ip)上工作得很好
- python - Python CMD 语法错误
- python-3.x - 为什么 numpy 为字符串数组占用这么多内存?
- ruby-on-rails - Ruby on rails:显示 pdf 文件
- sql - 将执行结果存储到表中
- javascript - 选择 DOM javascript 中的最后一个元素
- powershell - 测试 for/foreach 循环中是否存在远程 UNC 路径时的不同结果
- asp.net - 使用 IdentityServer4 授权没有登录的外部用户