get Text Width in TextView - Android User Interface

Android examples for User Interface:TextView Value

Description

get Text Width in TextView

Demo Code


//package com.java2s;
import android.content.Context;

import android.graphics.Paint;
import android.widget.TextView;

public class Main {

    public static float getTextWidth(String text, float textSize,
            Context context) {//w  ww .ja  v  a  2s .  c  o m
        TextView textView = new TextView(context);
        textView.setTextSize(textSize);
        Paint paint = textView.getPaint();
        return paint.measureText(text);
    }
}

Related Tutorials