简体   繁体   English

高度参数在Android中的怪异行为

[英]Weird behavior of height parameter in android

Here is what i am doing in my layout 这是我在布局中正在做的事情

  h = getWindowManager().getDefaultDisplay().getHeight(); 


Relative Layout = 60 dp = 90 using .getHeight()
Relative Layout = wrap content

Relative layout align bottom = 60 dp = 90

Now my width and height variables are showing height of 800. 现在我的width和height变量显示高度为800。

I am doing following things 我正在做以下事情

h = h - 180 // 

for (int i = 0 ; i < 10 ; i++)
        {
            TextView tv = new TextView(this);
            LayoutParams params  = new RelativeLayout.LayoutParams(w/10, h/10);

            wordsLayout.addView(tv,params);
}

I have made the code so that each textView goes directly below first one. 我已经编写了代码,以便每个textView都直接位于第一个下面。 Now according to code, the remaining height after subtracting heights of relative layouts should make the height of all textviews so that they fill up the empty space. 现在根据代码,减去相对布局的高度后的剩余高度应使所有textviews的高度高,以便它们填充空白空间。

However this works fine for w/10 or width but for height it always takes more space than empty space. 但是,这对于w / 10或宽度都可以正常工作,但对于高度,它总是比空白空间占用更多的空间。 I can't understand what is happening. 我不明白发生了什么。 How to adjust the height so that it only fills the space 如何调整高度,使其仅填充空间

您可以尝试使用相同的权重对所有这些权重进行加权:

LayoutParams params  = new RelativeLayout.LayoutParams(w/10, h/10,(float) 1.0);

我发现了问题,但我错过了title bar占据屏幕一定高度的事实。

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

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