Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a pixel width of a string in android?

Tags:

android

A string as "123456" showed in the screen. I want to get the width of that string .

like image 381
fordreamxin Avatar asked Nov 20 '13 06:11

fordreamxin


People also ask

How can I get my android width and height programmatically?

Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size. x; int height = size.

What is text view in android?

TextView is the user interface which displays the text message on the screen to the user. It is based on the layout size, style, and color, etc. TextView is used to set and display the text according to our specifications.

How do I find screen size on android?

<? xml version = "1.0" encoding = "utf-8" ?>


1 Answers

I dont tried, but maybe something like that:

mPaint = new Paint();
mPaint.setTextSize(64);
//...
float width = mPaint.measureText(text, 0, text.length());
like image 110
kai Avatar answered Sep 29 '22 08:09

kai