0

我的主要课程是这样的:

package projects.game.spinners;
import java.util.ArrayList;
import java.util.Collections;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.Menu;

public class MainActivity extends Activity
{

public Set set;
public Deal deal= new Deal();
public Player Name = new Player();
public computer comp1= new computer();
public computer comp2= new computer();
public computer comp3= new computer();
private Table table;
public Canvas canvas;

//public ArrayList<Domino> deck = set.getSet();
@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    set = new Set(this);
    table = new Table(this);
    ArrayList<Domino> deck = set.getSet();
    canvas = new Canvas();

    Collections.shuffle(deck);
    //deal.deal(Name, comp1, comp2, comp3, deck);
    //deck = deal.getDeck();
    table.playDomino(deck.get(0), 0, 0);
    table.invalidate();

    //table.onDraw(this);
    //Bitmap dsd = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

我的 ondraw 方法在表内,它看起来像这样:

package projects.game.spinners;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;
import android.widget.Toast;

public class Table extends View 
{
ArrayList<Position> table;
Context ctx;
Bitmap draw;

public Table(Context context)
{
    super(context);
    ctx=context;
    table=new ArrayList<Position>();
    draw = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
    this.setWillNotDraw(false);

}

public int getPossiblePlays()
{
    return 0;
}

public void playDomino(Domino domino, int x , int y)
{
    table.add(new Position(domino,x,y));

}

@Override
public void onDraw(Canvas canvas)
{
    super.onDraw(canvas);
    Toast.makeText(ctx,"Tag Already Done", Toast.LENGTH_LONG).show();
    canvas.drawBitmap(draw, 0,0, null);
    canvas.drawBitmap(table.get(0).getDomino().getImage(), 0,0, null);
}   
}

当它运行时,没有任何东西被绘制。我希望能够一遍又一遍地绘制它,因为如果有任何其他不使用不可调用类的方法来执行此操作,我会更改应该绘制的内容。

4

1 回答 1

0

似乎表格视图尚未添加到正在绘制的任何内容中。在你的主要活动的 onCreate 中尝试这样的事情:

table = new Table(this);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.IdOfYourMainLayoutFromYourManifest);
layout.addView(table);
于 2013-06-14T22:13:58.070 回答