mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-10-26 04:23:48 +08:00
fix(android): proper image view scaling for ScaleTypes.CENTER (#10899)
This commit is contained in:
@ -364,6 +364,17 @@ public class ImageView extends androidx.appcompat.widget.AppCompatImageView impl
|
||||
float uniformScale;
|
||||
float pivotX, pivotY;
|
||||
switch (this.getScaleType()) {
|
||||
case CENTER:
|
||||
uniformScale = 1;
|
||||
matrix.postTranslate((innerWidth - bitmapWidth) / 2, (innerHeight - bitmapHeight) / 2);
|
||||
matrix.postScale(uniformScale, uniformScale, innerWidth / 2, innerHeight / 2);
|
||||
canvas.clipRect(
|
||||
borderLeftWidth + (innerWidth - bitmapWidth * uniformScale) / 2,
|
||||
borderTopWidth + (innerHeight - bitmapHeight * uniformScale) / 2,
|
||||
borderLeftWidth + (innerWidth + bitmapWidth * uniformScale) / 2,
|
||||
borderTopWidth + (innerHeight + bitmapHeight * uniformScale) / 2
|
||||
);
|
||||
break;
|
||||
case FIT_CENTER: // aspectFit
|
||||
uniformScale = Math.min(fittingScaleX, fittingScaleY);
|
||||
matrix.postTranslate((innerWidth - bitmapWidth) / 2, (innerHeight - bitmapHeight) / 2);
|
||||
|
||||
Reference in New Issue
Block a user