• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problem with setLayoutParams and weight

jonathanrz

Member
I'm having problem changing the weight of a view by code.

I have two views, each one with weight of 1, when I change the weight of one to 2, then the opposite occurs, the view that have weight 1 occupies 66% of the screen and the view that have weight 2 occupies 33% of the screen.

The code:

View view = findViewById(R.id.view1);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams();

params.weight += 1f;

view.setLayoutParams(params);
 
Back
Top Bottom