Tuesday, October 11, 2011

How to set the weight of a view dynamically

If you want to change the weight-attribute of a view without the need of using the XML-file, you need to specify the LayoutParams:

Long weight = 1l;   //The"weight"int 
wrapContent = LayoutParams.WRAP_CONTENT;
LayoutParams lp = new LayoutParams(wrapContent, wrapContent, weight); //Creating a
paramTextView tv = new TextView(context);tv.setLayoutParams(lp); //Using the param for the weight

No comments:

Post a Comment