android - Get measure height of a TextView without add to the view hierarchy -


i following requirement.

  1. i need build tree leaves placed left , right, screen top bottom. can not put leaves in listview because tow leaves in same offset.

  2. i don't know height of items.

  3. i need pre-calculate height of dynamic content, such strings different lengths.

question:

how can pre-calculate height of sting put in textview widget described follows:

   <textview     android:id="@+id/note_content"     android:layout_width="40sp"     android:layout_height="wrap_content"     android:maxlines="5" /> 

enter image description here

create textview, set layoutparams, set text, call it's measure method , read measured values. btw can measure text, not textview (see staticlayout).

i think better create custom layout can implement "leaves measument" algorithms. check lesson. custom layout easy )


Comments