Created
January 10, 2020 02:37
-
-
Save boyan01/77fe25c53976ab8b9d54b113b225b942 to your computer and use it in GitHub Desktop.
自适应屏幕宽高
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static int[] calculateAutoFitWidthHeight(Size parentSize, Size originSize) { | |
int width = parentSize.getWidth(); | |
int height = parentSize.getHeight(); | |
int originW = originSize.getWidth(); | |
int originH = originSize.getHeight(); | |
float v1 = height / ((float) originH); | |
float v2 = width / ((float) originW); | |
float v = Math.min(v1, v2); | |
float targetWidth = originW * v + 0.5f; | |
float targetHeight = originH * v + 0.5f; | |
return new int[]{(int) targetWidth, (int) targetHeight}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment