0

I am creating elements programmatically in the onCreate() function of my activity. I am trying to calculate the height of a TextView that uses wrap_content for it's height, but cannot retrieve this value from this function.

Is there a better function in the activity's lifecycle to create these elements from or is there a way I can calculate the height needed for a TextView using a specific typeface, size, and linespace value and set it manually?

touhid udoy
  • 3,725
  • 2
  • 14
  • 30
Brandon Cornelio
  • 323
  • 2
  • 13

1 Answers1

1

In the lifecycle onCreate(), those views are drawing, so you are not able to get the view width / height at that time.

You can use View.post() to get the drawed (real) width / height, like the second item in https://stackoverflow.com/a/24035591/9035237 said.

Geno Chen
  • 4,361
  • 6
  • 19
  • 34