简体   繁体   中英

How best to display a grid of 4x4 images in an Android app/game?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM