對,我有三個類'遊戲','GridView'和'TokenView'(儘管只有第一個和最後一個類都需要幫助:D),我正在嘗試這裏做的是使用onTouch方法獲取我的'TokenView'類中的哪個列(getY)。Android畫布onTouch
遊戲:
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
int[][] pos = new int[mColumn][mRow];
/*Setting ball movement frame*/
FrameLayout tokenFrame = (FrameLayout) findViewById(R.id.widget39);
TokenView token = new TokenView(this);
tokenFrame.addView(token);
/*Setting drop area*/
FrameLayout gridFrame = (FrameLayout) findViewById(R.id.widget41);
GridView gridArea = new GridView(this);
gridFrame.addView(gridArea);
}
public int getPlayer(){
return player;
}
public boolean onTouch(View v, MotionEvent event){
if(){
//where I need help :D
}
return false;
}
TokenView:
public class TokenView extends View {
int Columns = 7;
public TokenView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Paint col = new Paint();
col.setColor(Color.rgb(0,103,231));
col.setStyle(Paint.Style.FILL);
Paint red = new Paint();
red.setAntiAlias(true); // smoothens edge
red.setColor(Color.RED);
red.setStyle(Paint.Style.FILL);
Paint yellow = new Paint();
yellow.setAntiAlias(true); // smoothens edge
yellow.setColor(Color.YELLOW);
yellow.setStyle(Paint.Style.FILL);
Rect myRect = new Rect();
canvas.drawRect(0, 0, getWidth(), getHeight(), col);
int columnWidth = canvas.getWidth()/7;
int rowHeight = (canvas.getHeight()/17);
int circleRadius = (canvas.getHeight()/6) - 163;
Game game = new Game();
int player = game.getPlayer();
for(int column = 0; column < Columns; column++)
{
if(player == 1){
canvas.drawCircle((columnWidth*column)+55, (rowHeight)+10, circleRadius, red);
}
else if(player == 2){
canvas.drawCircle((columnWidth*column)+55, (rowHeight)+10, circleRadius, yellow);
}
else if(player == 0){
canvas.drawCircle((columnWidth*column)+55, (rowHeight*1)+10, circleRadius, col);
}
}
}
提前
什麼類的類是Game類?你想讓程序做什麼? –
公共類遊戲擴展活動 而我只想獲取TokenView類的畫布中所觸及的令牌的列,以便我可以重新繪製柵格以將該令牌放入所選列的下一個可用行中。 – Oavatog