When you need to get the true height of textview, it is believed that many people will call TextView's GetHeight () method in the OnCreate function, simple and rude, indeed, this is a very convenient way, Unfortunately, TextView is not in oncreate at all, so it doesn't get the real height of the TextView, so we need to bind a listener to TextView, which is called after the render ends, as follows:
Viewtreeobserver observer = Contentview.getviewtreeobserver (); Observer.addongloballayoutlistener (new Ongloballayoutlistener () {@Overridepublic void Ongloballayout () {//TODO auto-generated method stub//Set text background if ( Contentview.getheight () < ScreenHeight) {scrollview.setbackgrounddrawable (bgdrawable);} else { Contentview.setbackgrounddrawable (bgdrawable);}});
Hope to be useful to everyone.
Android Get TextView Expand the height after rendering