Reputation: 7191
I have a linear layout with two textView. First textView has weight 40 and second 60. How I can change this weights in code in activity? This is possible? I want klick on the button and first weight should be 70 and second 30.
Upvotes: 0
Views: 85
Reputation: 4753
If you are importing an XML layout and you are not creating your layout dynamically, you can grab it like this:
TextView tv = (TextView) findViewById(R.id.your_textview_inside_the_linearlayout);
tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.1f));
otherwise it is just like this
TextView tv = new TextView(v.getContext());
tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
The last parameter is the weight.
Upvotes: 3