android - How to set button layout_gravity="fill_vertical" programmatically? -
i got gridlayout, , 2 or more button inside, , buttons must same width. problem when buttons having different line number of text, margintop of button different too. how can fix this? want buttons in same position of height.
thanks.
i try set gravity fill_vertical, not working.
gridlayout grid_neighbor = (gridlayout) findviewbyid(r.id.grid_neighbors); grid_neighbor.setcolumncount(4); (i = 0; < namelist.length; ++i) { button temp = new button(this); temp.settext(namelist[i]); linearlayout.layoutparams lp = new linearlayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); lp.gravity = gravity.fill_vertical; temp.setlayoutparams(lp); //temp.setgravity(gravity.fill_vertical); temp.setwidth(button_size); temp.setheight(button_size); grid_neighbor.addview(temp); } here picture:

this working too.
gridlayout grid_neighbor = (gridlayout) findviewbyid(r.id.grid_neighbors); grid_neighbor.setcolumncount(4); (i = 0; < namelist.length; ++i) { button temp = new button(this); temp.settext(namelist[i]); relativelayout.layoutparams lp = new relativelayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); lp.addrule(relativelayout.align_top, temp.getid()); temp.setlayoutparams(lp); //temp.setgravity(gravity.fill_vertical); temp.setwidth(button_size); temp.setheight(button_size); grid_neighbor.addview(temp); } this work! thanks.
gridlayout.spec speccolumn = gridlayout.spec(i%4); gridlayout.spec specrow = gridlayout.spec(i/4, gridlayout.top); grid_neighbor.addview(temp, new gridlayout.layoutparams(specrow, speccolumn));
if set gridlayout row's baseline doesn't resolve problem ? because if have different number of text lines in grid elements android automatically try align text same baseline, not align row elements.
edit: think it's more appropriate set rowspec.alignment = top (or 1 of alignments available http://developer.android.com/reference/android/widget/gridlayout.alignment.html ). please see http://developer.android.com/reference/android/widget/gridlayout.layoutparams.html further reference.
Comments
Post a Comment