我有這個代碼應該移動一個對象,但它仍然可以有人說什麼是錯?位圖不起作用
第一代碼
視圖類是我顯示該對象代碼。
import android.app.Activity;
import android.os.Bundle;
public class Game extends Activity {
Play View;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
View = new Play(this);
setContentView(View);
}
}
謝勝利代碼
這是代碼是該對象應當移動。
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;
public class Play extends View {
int Y=0;
Bitmap object;
public Play(Context context) {
super(context);
// TODO Auto-generated constructor stub object = BitmapFactory.decodeResource(getResources(), R.drawable.brid);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawColor(Color.GRAY);
canvas.drawBitmap(object, (canvas.getWidth()/2), Y, null);
if (Y < canvas.getHeight()){
Y +=10;
}else {
Y = 0;
}
}
}
好的thx真正有用的:) – user1241123 2012-02-29 20:18:16