[英]How to get width and height of an image from Glide
我已經將<ImageView />
height設置為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);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.