Search code examples
javaandroidtextviewwidthpixel

Get exact width of a textview in pixel programmatically (Android)


Using android, does anybody know how to get the exact width of a textview, in pixel, before it's displayed on the screen ? (programmatically) I've search a lot on the internet but I didn't found anything working.

Thank you

Links of the post I tried :

    1. With a Paint
      With measure
      With density

  • Solution

  • It was better that you had sent some code. Then we could help you more. But I think that you may use these methods:

    yourText.measure(0, 0);
    

    And then these codes:

    int width = view.getMeasuredWidth();
    int height = view.getMeasuredHeight();