get string Content Width With Size - Android android.graphics

Android examples for android.graphics:Paint

Description

get string Content Width With Size

Demo Code

import android.graphics.Paint;
import android.text.TextUtils;
import android.widget.TextView;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    private static float getContentWidthWithSize(String content,
            float textSize) {
        float width = 0f;

        Paint tPaint = new Paint();
        tPaint.setTextSize(textSize);/*from   w  ww  . j a v  a2s  . co m*/
        width = tPaint.measureText(content);

        return width;
    }

}

Related Tutorials