Java tutorial
//package com.java2s; import android.graphics.Paint; public class Main { public static void calculateOKTextSize(Paint paint, float stripeWidth, String[] text) { float minTextSize = 1000; for (int i = 0; i < text.length; ++i) { float currSize = setTextSizeForWidth(paint, stripeWidth, text[i]); if (currSize < minTextSize) minTextSize = currSize; } paint.setTextSize(minTextSize); } public static float setTextSizeForWidth(Paint paint, float desiredWidth, String text) { final float testTextSize = 100; paint.setTextSize(testTextSize); final float testWidth = paint.measureText(text); // Calculate the desired size as a proportion of our testTextSize. float desiredTextSize = testTextSize * desiredWidth / testWidth; // Set the paint for that size. paint.setTextSize(desiredTextSize); return desiredTextSize; } }