图片尺寸调整函数优化
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Wed Dec 10 20:11:13 HKT 2025
|
#Wed Dec 10 12:27:54 GMT 2025
|
||||||
stageCount=12
|
stageCount=12
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.12
|
baseVersion=15.12
|
||||||
publishVersion=15.12.11
|
publishVersion=15.12.11
|
||||||
buildCount=0
|
buildCount=1
|
||||||
baseBetaVersion=15.12.12
|
baseBetaVersion=15.12.12
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
setDefaultTransparentBackground();
|
setDefaultTransparentBackground();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mIvBackground.setVisibility(View.GONE);
|
mIvBackground.setVisibility(View.GONE);
|
||||||
|
|
||||||
// 计算原图比例
|
// 计算原图比例
|
||||||
@@ -211,37 +211,38 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
// 获取LinearLayout尺寸
|
// 获取LinearLayout尺寸
|
||||||
int llWidth = mLlContainer.getWidth();
|
int llWidth = mLlContainer.getWidth();
|
||||||
int llHeight = mLlContainer.getHeight();
|
int llHeight = mLlContainer.getHeight();
|
||||||
if (llWidth == 0 || llHeight == 0) {
|
// if (llWidth == 0 || llHeight == 0) {
|
||||||
postDelayed(new Runnable() {
|
// postDelayed(new Runnable() {
|
||||||
@Override
|
// @Override
|
||||||
public void run() {
|
// public void run() {
|
||||||
adjustImageViewSize();
|
// adjustImageViewSize();
|
||||||
}
|
// }
|
||||||
}, 100);
|
// }, 100);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 计算ImageView尺寸(保持比例,不超出LinearLayout)
|
if (llWidth != 0 && llHeight != 0) {
|
||||||
int ivWidth, ivHeight;
|
// 计算ImageView尺寸(保持比例,不超出LinearLayout)
|
||||||
if (mImageAspectRatio >= 1.0f) {
|
int ivWidth, ivHeight;
|
||||||
ivWidth = Math.min((int) (llHeight * mImageAspectRatio), llWidth);
|
if (mImageAspectRatio >= 1.0f) {
|
||||||
ivHeight = (int) (ivWidth / mImageAspectRatio);
|
ivWidth = Math.min((int) (llHeight * mImageAspectRatio), llWidth);
|
||||||
} else {
|
ivHeight = (int) (ivWidth / mImageAspectRatio);
|
||||||
ivHeight = Math.min((int) (llWidth / mImageAspectRatio), llHeight);
|
} else {
|
||||||
ivWidth = (int) (ivHeight * mImageAspectRatio);
|
ivHeight = Math.min((int) (llWidth / mImageAspectRatio), llHeight);
|
||||||
}
|
ivWidth = (int) (ivHeight * mImageAspectRatio);
|
||||||
|
}
|
||||||
|
|
||||||
// 应用尺寸
|
// 应用尺寸
|
||||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mIvBackground.getLayoutParams();
|
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mIvBackground.getLayoutParams();
|
||||||
params.width = ivWidth;
|
params.width = ivWidth;
|
||||||
params.height = ivHeight;
|
params.height = ivHeight;
|
||||||
mIvBackground.setLayoutParams(params);
|
mIvBackground.setLayoutParams(params);
|
||||||
mIvBackground.setScaleType(ScaleType.FIT_CENTER); // 确保居中平铺
|
mIvBackground.setScaleType(ScaleType.FIT_CENTER); // 确保居中平铺
|
||||||
mIvBackground.setVisibility(View.VISIBLE);
|
mIvBackground.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
|
||||||
//LogUtils.d(TAG, "ImageView尺寸:" + ivWidth + "x" + ivHeight);
|
//LogUtils.d(TAG, "ImageView尺寸:" + ivWidth + "x" + ivHeight);
|
||||||
//LogUtils.d(TAG, "=== adjustImageViewSize 完成 ===");
|
//LogUtils.d(TAG, "=== adjustImageViewSize 完成 ===");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDefaultTransparentBackground() {
|
private void setDefaultTransparentBackground() {
|
||||||
|
|||||||
Reference in New Issue
Block a user