android glide載入原圖顯示
阿新 • • 發佈:2019-01-27
final ViewGroup.LayoutParams lp = topicContentHolder.img.getLayoutParams();Glide.with(context) .load(subBeanList.get(position).imgUrl).asBitmap() .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap bitmap, GlideAnimation<? superBitmap> glideAnimation) { int width = bitmap.getWidth(); int height = bitmap.getHeight();
//40點引數是因為viewHolder裡面有距左距右各20DP的原因
lp.width= ScreenUtil.getScreenWidth(context)-(int)ScreenUtil.dpToPxInt(context,40); float tempHeight = height * ((float) lp.width / width); lp.height = (int) tempHeight; topicContentHolder.img.setLayoutParams(lp); topicContentHolder.img.setImageBitmap(bitmap); } });