alignment - ANDROID: Align dynamically created number pickers -


i creating alert dialog 2 number pickers , 2 textviews on top of each 1 select month , year, , textviews labels. creating them dynamically because seems easier fill min , max options (couldn't xml , layout inflator). can't make 2 pickers (and labels) centralized on alert dialog box. show on extreme left , extreme right, making ugly. on coding here is:

final numberpicker np1= new numberpicker(this);     final numberpicker np2= new numberpicker(this);     final textview t1=new textview(this);     final textview t2=new textview(this);               t1.settext("month");     t1.settextsize(20);      t2.settext("year");     t2.settextsize(20);              np1.setmaxvalue(12);     np1.setminvalue(1);     np2.setmaxvalue(2030);     np2.setminvalue(2000);           np1.setvalue(month);     np2.setvalue(year);      relativelayout linearlayout = new relativelayout(this);     relativelayout.layoutparams params = new relativelayout.layoutparams(20,20);     relativelayout.layoutparams numpicerparams1=new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content,relativelayout.layoutparams.wrap_content);     relativelayout.layoutparams numpicerparams2=new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content,relativelayout.layoutparams.wrap_content);     numpicerparams1.addrule(relativelayout.left_of);     numpicerparams2.addrule(relativelayout.align_parent_right);      linearlayout.setlayoutparams(params);     linearlayout.addview(np1, numpicerparams1);     linearlayout.addview(np2, numpicerparams2);     linearlayout.addview(t1,numpicerparams1);     linearlayout.addview(t2,numpicerparams2);      alertdialog.builder builder = new alertdialog.builder(this);     builder.settitle("chose month , year.");     builder.setview(linearlayout);     builder.setpositivebutton("ok",new dialoginterface.onclicklistener()      { (...) 

try this:

relativelayout relativelayout = new relativelayout(this); relativelayout.addrule(relativelayout.center_in_parent);   relativelayout linearlayout = new relativelayout(this); relativelayout.layoutparams params = new relativelayout.layoutparams(20,20); relativelayout.layoutparams numpicerparams1=new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content,relativelayout.layoutparams.wrap_content); relativelayout.layoutparams numpicerparams2=new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content,relativelayout.layoutparams.wrap_content); numpicerparams1.addrule(relativelayout.left_of); numpicerparams2.addrule(relativelayout.align_parent_right);  linearlayout.setlayoutparams(params); linearlayout.addview(np1, numpicerparams1); linearlayout.addview(np2, numpicerparams2); linearlayout.addview(t1,numpicerparams1); linearlayout.addview(t2,numpicerparams2);  relativelayout.addview(linearlayout); 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -