なぜこれが起こっているのかを理解するために、ここで非常に多くのスレッドを調べましたが、頭を包むことができません。
私のRelativeLayoutには、メニュー(alignedParentBottom)の上にある4つのHorizontalScrollViews(HSV)があります。
このメニューの上に4つのHSVを均等に配置したいと思います。
私の計算では、デバイスの高さを取得し、メニューの高さを減算してから4で割って、個々のHSVの高さを取得できるはずです。
ただし、各HSVの高さを設定すると、本来の高さよりも大きくなります。
(注:display.getHeight()は正しいサイズを返します。私は480x800デバイスを使用しており、deviceHeightを印刷すると800を返します)
これが私のコードです:
RelativeLayout menuLayout = (RelativeLayout)findViewById(R.id.menuLayout);
HorizontalScrollView row1 = (HorizontalScrollView)findViewById(R.id.row1);
HorizontalScrollView row2 = (HorizontalScrollView)findViewById(R.id.row2);
HorizontalScrollView row3 = (HorizontalScrollView)findViewById(R.id.row3);
HorizontalScrollView row4 = (HorizontalScrollView)findViewById(R.id.row4);
//get current device dimensions
Display display = getWindowManager().getDefaultDisplay();
deviceWidth = display.getWidth(); //returns 480
deviceHeight = display.getHeight(); //returns 800
int menuHeight = deviceWidth/5; // 480/5 = 96
int remainingSpace = deviceHeight - menuHeight; // 800 - 96 = 704
int rowHeight = (int) (remainingSpace/4); // 704/4 = 176
menuLayout.getLayoutParams().height = menuHeight;
row1.getLayoutParams().height = rowHeight;
row2.getLayoutParams().height = rowHeight;
row3.getLayoutParams().height = rowHeight;
row4.getLayoutParams().height = rowHeight;
このコードを実行すると、各行が大きすぎて、下部のメニューの下にプッシュされます。getHeight()を実行した場合。1行では、正しい高さ(176)であると表示されますが、明らかにそうではありません(4行が大きすぎてメニューの上のスペースに収まらないため)。
誰かがこれに光を当てることができますか?どうもありがとう!