Wednesday, May 8, 2013

programmatically-set-weight-for-button in android

You are create when Dynamically button then set weight without use xml.
then use it this code
  
LinearLayout.LayoutParams size = new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
size.weight = 1; 
 
Button btn = new Button(MainActivity.this);  
btn.setLayoutParams(size);
 
 
You have to use TableLayout.LayoutParams
TextView tv = new TextView(v.getContext());
tv.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.WRAP_CONTENT, 1f));  

1 comment:

  1. thanks
    https://www.facebook.com/groups/dandroid/689724367728314/?ref=notif&notif_t=like

    ReplyDelete