3 回答

TA貢獻1804條經驗 獲得超7個贊
maxWidth
android:scaleType="centerInside" android:adjustViewBounds="true"

TA貢獻1712條經驗 獲得超3個贊
下面的代碼使位圖完全符合相同大小的圖像視圖。獲取位圖圖像的高度和寬度,然后借助圖像視圖的參數計算新的高度和寬度。這給了你所需要的圖像與最佳的縱橫比。
int currentBitmapWidth = bitMap.getWidth();
int currentBitmapHeight = bitMap.getHeight();
int ivWidth = imageView.getWidth();
int ivHeight = imageView.getHeight();
int newWidth = ivWidth;
newHeight = (int) Math.floor((double) currentBitmapHeight *( (double) new_width / (double) currentBitmapWidth));
Bitmap newbitMap = Bitmap.createScaledBitmap(bitMap, newWidth, newHeight, true);
imageView.setImageBitmap(newbitMap)
好好享受吧。
- 3 回答
- 0 關注
- 422 瀏覽
添加回答
舉報