網(wǎng)上說的設置fitxy center啥都不適用了利朵,我已經(jīng)嘗試全猎莲。只能用最原始的辦法來實現(xiàn)這個功能。
首先布局文件就寫個imageview晌柬,寬高都設置成wrap_content即可,別的屬性不需要郭脂,接著就是測量繪制工作。
int screenWidth =getScreenWidth(mContext) - ViewUtils.dip2px(mContext, 30);? //頂格的寬度
Glide.with(mContext).asBitmap().load(bean).into(new BitmapImageViewTarget(picHolder.image){
@Override
? ? public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) {
super.onResourceReady(resource, transition);
? ? ? ?//1屿衅、使用Glide下載圖片轉成Bitmap莹弊,并獲取原始圖片的寬高:
? ? ? ? width = resource.getWidth();
? ? ? ? height = resource.getHeight();
? ? ? //2、修改寬度為屏幕寬度(一般要減去兩邊空白距離响迂,此案例左右留白15dp细疚,然后高度等比縮放)
? ? ? ? ViewGroup.LayoutParams lp =imageView.getLayoutParams();
? ? ? ? lp.height =height *screenWidth/width;? ?//高度等比縮放
? ? ? ? lp.width =screenWidth;
? ? ? ? imageView.setLayoutParams(lp);
? ? }
});