fur866
fur866

Reputation: 413

Weight property on android linear layout is not working

I am aware that there are a lot of questions out there with a similar question. However, most of them deal with horizontal orientation whereas my problem is with vertical orientation. And I have tried a few but they were of no help.

I am having issues with vertical orientation of linear layout. I have got this so far:

My layout parameter for this is as follows:

LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        lparams.weight = 1;
// And then simply adding this Layout param to all the widgets

However, when I set the height property to 0, I get nothing. My understanding is I should still get the same output since it should be assigning equal height to all of them based on the weight property. Can any one please help out?

Upvotes: 0

Views: 211

Answers (1)

fur866
fur866

Reputation: 413

I have finally figured out the problem. The problem was not with my understanding. My understanding is correct. However, when setting the content view I was passing in the same LayoutParams that I used for widgets. When, I set the height to 0, it would all set the height of everything to 0. To get around it, I just needed to create a new LayoutParam and pass that in with Content View.

Upvotes: 1

Related Questions