Skip to content

Instantly share code, notes, and snippets.

@nekocode nekocode/
Last active May 9, 2017

What would you like to do?
* 裁剪文本
private static String cutText(float textSize, String title, float maxWidth) {
final TextPaint textPaint = new TextPaint();
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) {
return str;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.