700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Android ImageView图片代码实现按屏幕宽度等比例缩放

Android ImageView图片代码实现按屏幕宽度等比例缩放

时间:2021-06-02 11:12:11

相关推荐

Android ImageView图片代码实现按屏幕宽度等比例缩放

/*** 设置图片根据屏幕宽度进行等比例缩放* @param imageView*/public static void setImageMatchScreenWidth(ImageView imageView){BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();if(bitmapDrawable == null)return;Bitmap bitmap = bitmapDrawable.getBitmap();if(bitmap == null)return;int defaultWidth = AppUtil.catchDisplayWidth(imageView.getContext());float scale = (float) defaultWidth / (float) bitmap.getWidth(); int defaultHeight = Math.round(bitmap.getHeight() * scale);LayoutParams params = imageView.getLayoutParams();params.width = defaultWidth;params.height = defaultHeight;imageView.setLayoutParams(params);}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。