Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Paint; public class Main { protected static Object[] createWrappedLine(String block, Paint paint, float spaceOffset, float maxWidth) { float cacheWidth = maxWidth; float origMaxWidth = maxWidth; String line = ""; for (String word : block.split("\\s")) { cacheWidth = paint.measureText(word); maxWidth -= cacheWidth; if (maxWidth <= 0) { return new Object[] { line, maxWidth + cacheWidth + spaceOffset }; } line += word + " "; maxWidth -= spaceOffset; } if (paint.measureText(block) <= origMaxWidth) { return new Object[] { block, Float.MIN_VALUE }; } return new Object[] { line, maxWidth }; } }