android - Setting parameters on child views of a RelativeLayout -
i'm having trouble finding syntax need use set paramters on child views of relative layout. have root relative layout want set 2 child textviews next each other this
---------- --------- | second | | first | ---------- ---------
so have
public class rl extends relativelayout{ public rl(context){ textview first = new textview(this); textview second = new textview(this); first.settext('first'); first.setid(1); second.settext('second'); second.setid(2); addview(first, new relativelayout.layoutparams(layoutparams.wrap_content, layoutparams.wrap_content, layoutparams.allign_parent_right ???); addview(first, new relativelayout.layoutparams(layoutparams.wrap_content, layoutparams.wrap_content, layoutparams.allign_right_of(first.getid()) ???); } }
how set relative alignments?
public class rl extends relativelayout { public rl(context context) { super(context); textview first = new textview(context); textview second = new textview(context); first.settext("first"); first.setid(1); second.settext("second"); second.setid(2); relativelayout.layoutparams lpsecond = new relativelayout.layoutparams( layoutparams.wrap_content, layoutparams.wrap_content); addview(second, lpsecond); relativelayout.layoutparams lpfirst = new relativelayout.layoutparams( layoutparams.wrap_content, layoutparams.wrap_content); lpfirst.addrule(relativelayout.right_of, second.getid()); addview(first, lpfirst); } }
you need align_parent_right if want right edge of view line right edge of parent. in case, push 'first' view off side of visible area!
Comments
Post a Comment