How can I draw several rectangles in a row programmatically?

Viewed 8795

I want to put several rectangle i a row. But because I'm new to Android and specially to Bitmap, Canvas and so on, I need some help.

It should look like this, only with rectangles:

enter image description here

I have created one rectangle with this code:

        Paint paint = new Paint();
        paint.setColor(Color.parseColor("#CD5C5C"));
        Bitmap bg = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bg); 
        canvas.drawRect(50, 80, 200, 200, paint); 
        RelativeLayout ll = (RelativeLayout) findViewById(R.id.rect);

        ImageView iV = new ImageView(this);
        iV.setImageBitmap(bg);

        ll.addView(iV);

But now I dont know how to create more rectangles with different colors in a row. I'm really new and sorry for that maybe stupid question but I need help for it.

Can anybody guide me how to do this in the best way?

3 Answers
Related