Get Measure Height Of A Textview Without Add To The View Hierarchy
I get following requirement. I need to build a tree with leaves placed left and right, from the screen top to the bottom. I can not put the leaves in a ListView because tow leaves
Solution 1:
Create textView, set LayoutParams, set text, call it's measure method and read measured values. BTW you can measure text, not textView (see StaticLayout).
I think you better create your custom layout where you can implement all your "leaves measument" algorithms. Check this lesson. Custom layout is very easy )
Solution 2:
Use this for calculate height and width your textview
textView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
publicvoidonGlobalLayout() {
h=textView.getHeight();
w=textView.getWidth();
textView.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
But in xml do not assign textview as a wrap content. Because it will give you value 0.
Post a Comment for "Get Measure Height Of A Textview Without Add To The View Hierarchy"