Java tutorial
//package com.java2s; import android.graphics.Paint; public class Main { final static String SYSTEM_NEWLINE = "\n"; private static String wrap(String s, float width, Paint p) { String[] str = s.split("\\s"); //regex StringBuilder smb = new StringBuilder(); //save memory smb.append(SYSTEM_NEWLINE); for (int x = 0; x < str.length; x++) { float length = p.measureText(str[x]); String[] pieces = smb.toString().split(SYSTEM_NEWLINE); try { if (p.measureText(pieces[pieces.length - 1]) + length > width) smb.append(SYSTEM_NEWLINE); } catch (Exception e) { } smb.append(str[x] + " "); } return smb.toString().replaceFirst(SYSTEM_NEWLINE, ""); } }