android - Programatically added Views not behaving -


i've created many custom views , trying add them fragment. added can't seem them go want. there should 2 columns , 3 rows ends 1 column of custom views stacked on top of 1 another. here code add views , set layout params fragment layout:

relativelayout fm = (relativelayout) view.findviewbyid(r.id.fragmentlayout);      relativelayout.layoutparams params = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content);      params.addrule(relativelayout.align_parent_left, relativelayout.true);     customimages cs = new customimages(getactivity());     cs.setid(r.id.one);     cs.setlayoutparams(params);      params = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content);     params.addrule(relativelayout.align_parent_right, relativelayout.true);     params.addrule(relativelayout.right_of, cs.getid());     customimages2 cs2 = new customimages2(getactivity());     cs2.setid(r.id.two);     cs2.setlayoutparams(params);      relativelayout.layoutparams params2 = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content);     params2.addrule(relativelayout.align_parent_left, relativelayout.true);     params2.addrule(relativelayout.below, cs2.getid());     customimages3 cs3 = new customimages3(getactivity());     cs3.setid(r.id.three);     cs3.setlayoutparams(params);      relativelayout.layoutparams params3 = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content);     params3.addrule(relativelayout.align_parent_right, relativelayout.true);     params3.addrule(relativelayout.right_of, cs3.getid());     customimages4 cs4 = new customimages4(getactivity());     cs4.setid(r.id.four);     cs4.setlayoutparams(params);      relativelayout.layoutparams params4 = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content);     params4.addrule(relativelayout.align_parent_left, relativelayout.true);     params4.addrule(relativelayout.below, cs4.getid());     customimages5 cs5 = new customimages5(getactivity());     cs5.setid(r.id.five);     cs5.setlayoutparams(params); 

cs3.setlayoutparams(params); cs4.setlayoutparams(params); cs5.setlayoutparams(params); 

i believe params there should replaced params2, params3 , params4 respectively.

update:
also, should specify layout_below views not on top, , correctly:

params2.addrule(relativelayout.below, cs.getid()); // not cs2 params3.addrule(relativelayout.below, cs2.getid()); // add params4.addrule(relativelayout.below, cs3.getid()); // not cs4 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -