1

I would like to draw the shape like bellow. After some user event the program have to redraw it with different paramteres: the number and width of boxes were change. It represents busy and free time slots in a period.

sample

The entire drawing will be in a view control. I know the pseudo-code only:

int left = 1;
int upper = 1;
int bottom = 50;
foreach( myDataType item : List<myDataType> ) {
    Paint myPaint = new Paint();
    myPaint.setColor( Color.RED );
    Draw( left,  upper, left + item.width, bottom, myPaint );  // red one
    left += item.width;
    myPaint.setColor( Color.GREEN );
    Draw( left,  upper, left + item.nextGap, bottom, myPaint );  // green one
    left += item.nextGap;
}

Any ideas wellcome, thanx!

Franziee
  • 621
  • 11
  • 28
  • 4
    Create a custom view by extending View, then use your pseudo code in the onDraw() method. – Simon Nov 26 '12 at 20:55
  • This question is similar (not similar enough to close this one as duplicate): http://stackoverflow.com/questions/4439456/how-to-create-a-simple-custom-view – Kevin Nov 26 '12 at 20:59
  • And these articles discuss how to make a custom view: http://developer.android.com/training/custom-views/index.html – Kevin Nov 26 '12 at 21:00
  • @Simon thank you. How can I handle the events? The onDraw() draws one configuration but it will be changed and the program have to redraw the shape. So how can I do it? Is it possible to redraw the object? – Franziee Nov 26 '12 at 21:58
  • 1
    onDraw is called everytime the view draws itself. To force it to draw, for example after the parameters are changed, just call `view.invalidate();` – Simon Nov 27 '12 at 09:47

0 Answers0