2017-10-25 9 views
0

私は8x8ボタンのGridLayoutを作成しようとしています(掃海艇のような)。私は同じ幅を持つすべての重量を管理していますが、それは4つのボタンまでうまく動作します。列4に5番目のボタンを追加すると、幅がフルスクリーンに拡大されます。これは私のxml:4ボタンでボタンが4列を超えるグリッドレイアウト

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/GridLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="8dp" 
    android:columnCount="8" 
    android:orientation="horizontal" 
    android:rowCount="8" 
    tools:context=".MainActivity"> 

    <Button 
     android:id="@+id/b1" 
     android:layout_column="0" 
     android:layout_columnWeight="1" 
     android:layout_row="0" 
     android:text="B" /> 

    <Button 
     android:id="@+id/b2" 
     android:layout_column="1" 
     android:layout_columnWeight="1" 
     android:layout_row="0" 
     android:text="B" /> 


    <Button 
     android:id="@+id/b3" 
     android:layout_column="2" 
     android:layout_columnWeight="1" 
     android:layout_row="0" 
     android:text="B" /> 
    <Button 
     android:id="@+id/b4" 
     android:layout_column="3" 
     android:layout_columnWeight="1" 
     android:layout_row="0" 
     android:text="B" /> 
</GridLayout> 

デザイン:4 button

私は4列に5番目のボタンを追加する場合:button expands

ありがとうございました!

+0

あなたの問題に似たこのリンクに行くhttps://stackoverflow.com/questions/10016343/gridlayout-not-gridview-how-to-stretch-all-children-evenly –

答えて

0

様々な画面用のレイアウトを作成してみてくださいが

ldpi (low) ~120dpi 
mdpi (medium) ~160dpi 
hdpi (high) ~240dpi 
xhdpi (extra-high) ~320dpi 
xxhdpi (extra-extra-high) ~480dpi 
xxxhdpi (extra-extra-extra-high) ~640dpi 

のサイズ私は、さまざまな画面上でそれを試してみました問題は、最大一度あるレイアウト

0

の出た場合、それは私のために働いたが、ボタンが拡大サイズ5番目のボタンのスペースがないので、行全体を占めています。

あなたは問題を解決する別々のXMLファイルを維持する必要があります。

関連する問題