1

I have a problem in GridLayout. I want to display 49 buttons inside but it does not work 7 column and 7 row

XML :

<GridLayout
    android:id="@+id/MYG"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="7"
    android:orientation="horizontal"
    android:rowCount="7">
</GridLayout>

Code Java (Android Studio).

Button[] myButton=new Button[49];
for(i=0;i<49;i++) {
    myButton[i] = new Button(this);
    GridLayout.LayoutParams param =new GridLayout.LayoutParams();
    myButton[i].setText(String.valueOf(i));
    myButton[i].setBackgroundResource(R.drawable.buttonvid);
    colon.addView(myButton[i]);
}

The last two are hidden in each row.

The result : The last two are hidden in each row

kit
  • 1,166
  • 5
  • 16
  • 23
vinom
  • 17
  • 3

1 Answers1

1

There is no issue in your code! Only thing is that 2 of your columns are not visible on the screen due to small screen size.

Possible Solution: your can either keep the size of each box smaller so that all boxes can be shown or some other way to keep them on available screen.

enter image description here

Muhammad waris
  • 314
  • 1
  • 10