Last active
May 9, 2017 09:07
-
-
Save nekocode/9f8cbeb950b796d2663749e5375999ea 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 String cutText(float textSize, String title, float maxWidth) { | |
final TextPaint textPaint = new TextPaint(); | |
textPaint.setTextSize(textSize); | |
if (textPaint.measureText(title) < maxWidth) | |
return title; | |
int i; | |
String str = null; | |
for (i = title.length(); i > 0; i--) { | |
str = title.substring(0, i) + "..."; | |
float width = textPaint.measureText(str); | |
if (width < maxWidth) { | |
break; | |
} | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment