I have a view made up of TableLayout, TableRow and TextView
. I want it to look like a grid. I need to get the height and width of this grid. The methods
I tried to use onGlobalLayout()
to do some custom formatting of a TextView
, but as @George Bailey noticed, onGlobalLayout()
is indeed called twice: once on the initial layout path, and second time after modifying the text.
View.onSizeChanged() works better for me because if I modify the text there, the method is called only once (during the layout pass). This required sub-classing of TextView
, but on API Level 11+ View. addOnLayoutChangeListener() can be used to avoid sub-classing.
One more thing, in order to get correct width of the view in View.onSizeChanged()
, the layout_width
should be set to match_parent
, not wrap_content
.