/** | |
* 裁剪文本 | |
*/ | |
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