ui thread - Android view not shown after addView method -


i have issue viewgroup.addview() method. use code add new view layout:

talbelayout parent = (tablelayout)findviewbyid(r.id.this_does_not_matter); parent.removeallviews(); //this view group contains @ start textview tv = new textview(this); tv.settext("some text"); tablelayout.layoutparams lp = new tablelayout.layoutparams(tablelayout.layoutparams.match_parent, tablelayout.layoutparams.wrap_content); tv.setlayoutparams(lp); parent.addview(tv); 

and after cant see textview. more that, parent.getchildcount() returns correct values (1 if try add 1 child). in onclick() method of parent view try width , height of textview , of equals 0. calling requestlayout(), invalidate() , measure(500, 50) tableview , parent has no effect. try add new view of view.post(runnable), although code executed in ui thread.

i confused. don't understand happens. can explain me doing wrong?

one interesting moment: setlayoutparams() has no effect. if set params width=500 , height=50, in onclick method params width=-1 , height=-1.

code after tablerow added:

tablelayout parent = (tallelayout)findviewbyid(r.id.this_does_not_matter); parent.removeallviews(); //this view group contains @ start textview tv = new textview(this); tv.settext("some text"); tablelayout.layoutparams lp = new tablelayout.layoutparams(500, 50); tablerow.layoutparams tlp = new tablerow.layoutparams(500, 50); tablerow tr = new tablerow(this); tr.addview(tv, tlp); parent.addview(tr, lp); parent.invalidate(); parent.requestlayout(); 

i found 1 more interesting thing. activity runs tabhost. , "addview bug" appears if activity first selected in tabhost. if @ first time start activity tab, works fine.

i found solution. if switch off layout animation android:animatelayoutchanges="false" works fine. still have no idea why happens. if know reason of behavior, interesting me.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -