[英]Ondraw method is not being called
I have my main class like so: 我的主要课程如下:
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;
}
}
my ondraw method is inside table and it looks like this: 我的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);
}
}
When this is run nothing is being Draw. 运行此命令时,没有任何内容被绘制。 I want to be able to draw this over and over as i change what should be drawn if there is any other way to do this that does not use a none callable class. 我希望能够一遍又一遍地绘制此图形,因为如果我有其他方法可以使用不调用none的可调用类,则可以更改应绘制的图形。
Seems like the table View hasn't been added to anything that's being drawn. 似乎表View尚未添加到正在绘制的任何内容中。 Try something like this in your main activity's onCreate: 在您的主要活动的onCreate中尝试以下操作:
table = new Table(this);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.IdOfYourMainLayoutFromYourManifest);
layout.addView(table);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.