0

I am trying to program a game of Ludo in Android. I have the general progression and internal tables in mind, but I cannot find a way to make an x by y table of images (squares).

tab[x][y] is defined by the resolution of the device, x being the number of rows and y the muber of columns. My problem is that I only can't a way to implement this table into my view in a way that allows me to change the images (as new pieces are added to the board and move around the board)

I've been searching for an answer to this, but I only found examples for image arrays which are NOT meant to be interchangable or are about standalone images. I am green in android and I currently get easily lost in the online libraries and I thank anyone for a response.

Added (what little I've written about this so far (I am willing not to use bitmaps if a better solution presents itself)):

public class Game extends View{
public Game(Context context) {
    super(context);

    Button new_game_button = (Button) findViewById (R.id.button1);
    View game_board = (View) findViewById (R.id.view1);

    new_game_button.setOnClickListener (new OnClickListener() {
        public void onClick (View view) {

        }
    });

    Resources res=getResources();
    Bitmap empty = BitmapFactory.decodeResource(res, R.drawable.empty);
    Bitmap redpl = BitmapFactory.decodeResource(res, R.drawable.red);
    Bitmap yellowpl = BitmapFactory.decodeResource(res, R.drawable.yellow);
    Bitmap bluepl = BitmapFactory.decodeResource(res, R.drawable.blue);
    Bitmap greenpl = BitmapFactory.decodeResource(res, R.drawable.green);
    Bitmap redhome = BitmapFactory.decodeResource(res, R.drawable.redhome);
    Bitmap yellowhome = BitmapFactory.decodeResource(res, R.drawable.yellowhome);
    Bitmap bluehome = BitmapFactory.decodeResource(res, R.drawable.bluehome);
    Bitmap greenhome = BitmapFactory.decodeResource(res, R.drawable.greenhome);

    game_board.setOnClickListener (new OnClickListener() {
        public void onClick (View view) {

        }
    });

}
}
4

1 回答 1

0

我可能会考虑使用TableLayout。如果您有固定的网格大小,那么您最好使用 XML 进行布局,并可能以编程方式将ImageView设置到表中的每个单元格中。对于每个 ImageView,您可以附加一个 onTouch 回调以允许移动等。

于 2012-05-13T19:58:44.017 回答