简体   繁体   English

Android线性布局上的Weight属性不起作用

[英]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. 但是,当我将height属性设置为0时,我什么也没得到。 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. 我的理解是,我仍应获得相同的输出,因为它应基于weight属性为所有这些物体分配相等的高度。 Can any one please help out? 有人可以帮忙吗?

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. 但是,设置内容视图时,我传递的是与小部件相同的LayoutParams。 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. 当我将高度设置为0时,会将所有东西的高度都设置为0。要解决该问题,我只需要创建一个新的LayoutParam并将其传递给Content View。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM