codingCat
codingCat

Reputation: 2406

Android: How to determine the Length of text (in pixels)?

I am building an app and based on the content and screen size I want to dynamically set the font size to fill the entire screen.

Is there a way to determine the width of a line of text (in pixels)? I want to avoid the flicker that trial and error can present the user. Can it be done without first displaying a TextView?

Upvotes: 1

Views: 964

Answers (1)

Romain Guy
Romain Guy

Reputation: 98501

The Paint class has a measureText method for this purpose :)

Upvotes: 7

Related Questions