简体   繁体   中英

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.

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. 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.

However this works fine for w/10 or width but for height it always takes more space than empty space. 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占据屏幕一定高度的事实。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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