Take the 2-minute tour ×

I'm trying to create a small BrickBreaker game.

I have a MainActivity.java, BrickBreakerView.java, and a Paddle.java so far. BrickBreakerView extends the ViewGroup class, and Paddle extends the View class. I'm hoping to be able to add a Paddle, Bricks, Ball, and a Scoreboard (custom view classes that I will create) to the BrickBreakerView. Essentially, BrickBreakerView will control the interactions of these views.

The MainActivity's xml layout adds a BrickBreakerView to the layout. The BrickBreakerView instantiates a Paddle in the onCreate method, and it also adds the paddle as a subview (addView()).

I've overwritten the Paddle's onDraw method to draw a blue rectangle given X and Y positions. However, when I run my program, I don't see anything on screen. I have tested with Log.d to check that the BrickBreakerView's and Paddle's constructors ARE being called.

Thanks for any help! Also, I am new to Android development, and if you guys could give me some comments regarding the structure of my game, I would be grateful :D!

Here are the relevant pieces of code.

This is called in my main activity:


My main.xml looks like: .BrickBreakerView


The BrickBreakerView.java class:

 public class BrickBreakerView extends ViewGroup{

public BrickBreakerView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Paddle paddle = new Paddle(context, 100, 400);
    Log.d("print", "Brick Breaker View constructor");

    // TODO Auto-generated method stub
    Log.d("print", "onLayout called");


The Paddle.java class:

 public class Paddle extends View{

private int myX, myY;

public Paddle(Context context, int xPos, int yPos) {
    // TODO Auto-generated constructor stub
    Log.d("print", "paddle constructor");
    myX = xPos;
    myY = yPos;
public void setXPosition(int x) {
    myX = x;
public void setYPosition(int y) {
    myY = y;
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub

    Log.d("print", "onDraw called");
    Paint paint = new Paint();
    canvas.drawRect(myX, myY, myX+100, myY+50, paint);


share|improve this question
add comment

1 Answer

Make the paddle instance a member var of brick breaker view. Create and add it to the view group - you are doing this. In onLayout, put paddle.layout(0,0,100,100)

share|improve this answer
add comment

Your Answer


