I have a class extend view, I create the object when I touch some area
on the main activity. But then it cannot draw the picture, I tried
onDraw method / create a canvas and then draw it, but both not work.
public class MyGame extends Activity {
GameView mGameView = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN ,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
MainView();
}
/**This function give the response when click on start*/
public void MainView(){
mGameView = new GameView(MyGame.this);
setContentView(R.layout.main);
ImageView MainView = (ImageView)findViewById(R.id.MainMenu);
MainView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent e) {
float x = e.getX();
float y = e.getY();
if( x > 1 && x < 98 && y > 352 && y < 449){//If
the user click on
the "StartGame" button
mGameView = new GameView(MyGame.this);
return true;
}
return false;
}
});
}
}
public class GameView extends View{
Context mcontext = null;
public GameView(Context context) {
super(context);
mcontext = context;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.gameboard, null);
Canvas canvas = new Canvas(bitmap);
this.draw(canvas);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.gameboard, null);
canvas.drawBitmap(bitmap, 0, 0, new Paint());
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en