1

I am trying to retrieve the width of my TextView which is loaded with text. Here is the code I use,

txt_MyText.measure(0, 0);
float textViewWidth = txt_MyText.getMeasuredWidth();

Now this code returns the value as 25882.0

I am testing this on Samsung Galaxy S6 Edge which has a Screen Dimension of Samsung Galaxy S6, S6 Edge 5.1″ 1440×2560

I am not sure in what unit this value is returned. In my XML I am setting the TextView width as WRAP_CONTENT.

How to get the width of the text view in PIXELS.

Thanks.

Zach
  • 9,989
  • 19
  • 70
  • 107

2 Answers2

0

This is what you're looking for

What is the difference between getWidth/Height() and getMeasuredWidth/Height() in Android SDK?

Thiago Valle
  • 449
  • 1
  • 6
  • 20
-1
txt_MyText.getWidth() // this will get you the view's width
txt_MyText.getHeight() // this will get you the view's height

the returned value will be in pixels

Gil Goldzweig
  • 1,809
  • 1
  • 13
  • 26