Android ImageView图片代码实现按屏幕宽度等比例缩放
生活随笔
收集整理的這篇文章主要介紹了
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);}
轉載于:https://www.cnblogs.com/xiakexinghouzi/p/4741311.html
總結
以上是生活随笔為你收集整理的Android ImageView图片代码实现按屏幕宽度等比例缩放的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: varchar 保存英文中文区别。
- 下一篇: laravel controller