Incorrect Android Button Width in TableLayout -


i have series of buttons want add different rows in tablelayout. each button needs have different width. however, each button's width being set equal button maximum width. can let me know how fix please?

        <tablelayout             android:id="@+id/table_to_fill"             android:layout_width="wrap_content"             android:layout_height="wrap_content" >              <tablerow                 android:layout_width="wrap_content"                 android:layout_height="wrap_content" >                  <textview                     android:id="@+id/cat"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:text=""                     android:textsize="12sp"                     android:textstyle="bold"                     android:typeface="serif" >                 </textview>                  <textview                     android:id="@+id/num_high"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:text=""                     android:textsize="12sp"                     android:textstyle="bold"                     android:typeface="serif" >                 </textview>             </tablerow>         </tablelayout> 

java code:

    (int =0; i< 5; ++i){         tablerow row = new tablerow(this);         textview t1 = new textview(this);         t1.settext("cat: ");         t1.settextsize(12);         row.addview(t1);         button b1 = new button(this);          b1.settext(numhighrisk.tostring());         b1.settextsize(12);         b1.setpadding(0, 0, 0, 0);         row.addview(b1);         int width;         if (i > 2)             width = 20;         else             width = 40;         int heightdp = (int) (25 * scale + 0.5f);         int widthdp = (int) (width * scale + 0.5f);           viewgroup.layoutparams params = b1.getlayoutparams();         params.height = heightdp;         params.width = widthdp;         b1.setlayoutparams(params);              tablelayout.layoutparams rowparams = new tablelayout.layoutparams(tablerow.layoutparams.wrap_content, tablerow.layoutparams.wrap_content);         table.addview(row,rowparams);     } 

(each button has same width using code)

yeah in table layout items have same size in order make them aligned , can 1 thing try giving margin button size reduce, different margin different button. example,

 android:layout_marginleft="40dp"  android:layout_marginright="40dp" 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -