2017-10-25 1 views
0

저는 지뢰밭과 같은 8x8 버튼의 GridLayout을 만들려고합니다. 나는 모든 너비가 같은 가중치를 관리하지만 4 버튼까지는 잘 작동한다. 열 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 버튼 : 나는 4 열 5 버튼을 추가 할 때 4 button

가 : button expands

감사합니다 이건 내 XML입니다! 최대 한 번입니다

+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

문제에서 가면 버튼 확장 너비가 도달하면 다섯 번째 버튼에 대한 공간이 없으므로 전체 행을 차지합니다.

당신은 문제를 해결할 별도의 XML 파일을 유지해야합니다.