Android examples for User Interface:TextView
adjust TextView Text Size
//package com.java2s; import android.text.TextPaint; import android.widget.TextView; public class Main { public static void adjustTextSize(TextView tv) { float size = tv.getPaint().getTextSize(); TextPaint textPaint = tv.getPaint(); float stringWidth = textPaint.measureText(tv.getText().toString()); int textViewWidth = tv.getWidth(); if (textViewWidth > stringWidth) { float percent = (textViewWidth / stringWidth); textPaint.setTextSize(size * percent); }//from w w w . ja va 2 s . c o m } }