Pages

BitmapDrawable

I sense that they stayed up late late into the night to devise something that is so tricky to use.
 
I've been drawing lines and couldn't work out why they were so "fat". Eventually I realized that they are affected by Gravity.
 
I also struggled with trying to draw more than one line on a bitmap and in different colours. The only saving grace is the canvas.drawLines method which at least allows a series of lines to be drawn on a single bitmap (but only in a single colour).
 
I've ended it up with something like this:
 
BitmapDrawable baseLine = new BitmapDrawable(Bitmap.createBitmap(300, 6, Bitmap.Config.ALPHA_8));
baseLine.setGravity(Gravity.BOTTOM | Gravity.LEFT);
 
float[] points = {
/* base */0, 3, lineEnd, 3,
/* starttick */0, 1, 0, 5,
/* endtick */lineEnd, 1, lineEnd, 5 };
 
baseLineCanvas.drawLines(points, baseLinePaint);