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
Post a Comment