measure Text Width in TextView - Android User Interface

Android examples for User Interface:TextView

Description

measure Text Width in TextView

Demo Code


//package com.java2s;

import android.text.TextPaint;
import android.text.TextUtils;

import android.widget.TextView;

public class Main {
    public final static int measureTextWidth(TextView view, String text) {
        if (TextUtils.isEmpty(text)) {
            return 0;
        }/*from  w  w  w. ja  v a2 s. c o  m*/

        TextPaint paint = view.getPaint();
        int width = (int) paint.measureText(text);
        return width;
    }
}

Related Tutorials