Reputation: 1451
I'm learning android development and I'm doing a minesweeper. So I use a tableLayout to display the board. But how can I do to adapt the width of the cells to fit the screen ?
Currently my cells are fixed so the grid expand beyond the side of the screen...
How can I take the entire screen width for my tableLayout ?
Thanks.
Upvotes: 3
Views: 2737
Reputation: 7024
since you are creating your cells dynamically, you can calculate the height and width of the screen using:
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
and then set your cell size accordingly.
Upvotes: 3
Reputation: 13541
This is done through using simple properties found inside of your layout file xml file. Specifically you want to set the
android:layout_width="fill_parent"
This will tell the layout to consume the ENTIRE width of its parent.
Upvotes: 0