I am currently creating a whack-a-mole type game for a university assignment and I need to know how best to display the holes on screen. I have had a look at GridView, GridLayout and TableLayout and am confused as to which one I should pick considering I later need to make various clickables pop up from each hole. The Overall screen should simply have a banner at the top that will display score, lives etc. and a pause button at the bottom with a 4x4 grid in the middle displaying the holes. I am relatively new to XML and Java so any advice would be greatly appreciated.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I think, easy enough with GridLayout, but then you have limitation of using SDK > 14.
Easy 4 lines of code to make 4 x 4 grid:
gridContainer = new GridLayout(this);
gridContainer.setColumnCount(4);
YOUR_OWN_VIEW.addView(gridContainer);
for(int i = 0; i < 16; i++)
{
ImageView img = new ImageView(this);
img.setImageDrawable(this.getResources().getDrawable(R.drawable.ic_launcher));
gridContainer.addView(img, Math.max(0, gridContainer.getChildCount()));
}
code above is for reference. May you need to change the images, size per your need. "YOUR_OWN_VIEW" - change to your view name.