How do you get buttons in Android to stretch/shrink automatically on screen?

Retitten

New Member
XML Code:\[code\]<GridLayout android:id="@+id/grid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@+id/step" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_below="@+id/menu" ></GridLayout>\[/code\]The above code creates a grid to allow an easy layout for the buttons being created.Java code:\[code\]GridLayout grid = (GridLayout)findViewById(R.id.grid);grid.setColumnCount(10);grid.setRowCount(10);cells = new Button[100];for (int i = 0; i < 100; i++) { cells = new Button(this); if (gen.nextInt(3) % radiofill == 0) //[0,3) cells.setBackgroundColor(Color.WHITE); else cells.setBackgroundColor(Color.BLACK); cells.setClickable(true); cells.setOnClickListener(new OnClickListener() { public void onClick(View v) { v.setBackgroundColor(Color.BLACK); } }); grid.addView(cells); }\[/code\]In this code 100 buttons are being created and added to an array that is eventually added to the GridLayout created in the XML.All the buttons seem to be created, placed, and working as they are meant to but the buttons are so large they do not fit in the screen on the phone. How can I make it where the buttons fill the GridLayout fully without over or under flowing? In this instance 100 buttons are created but the program is designed to allow the creation of multiple types of perfect square numbers (4, 9, 16, 25, 36, 49) so the GridLayout needs to be flexible.
 
Back
Top