Question

I have a custom view that draws several different things on screen. Each one has its own paint object. Everything is drawing fine EXCEPT the text. It works just fine in Gingerbread, but ICS+ has no text.

Here is my on draw method:

protected void onDraw(Canvas canvas)
{
   canvas.save(Canvas.MATRIX_SAVE_FLAG);
   canvas.scale(getWidth(), getHeight());

   drawGrid(canvas);
   drawHeader(canvas);
   drawSelected(canvas);
   drawDays(canvas);
   drawToday(canvas);

   canvas.restore();
}

Grid, Selected, and Today work fine. Header and Days are the text drawing and they don't work.

Here is the drawHeader method:

private void drawHeader(Canvas canvas)
{
   canvas.drawText("Sun", DAYS[0], .05f, paintDaysOfTheWeek);
   canvas.drawText("Mon", DAYS[1], .05f, paintDaysOfTheWeek);
   canvas.drawText("Tues", DAYS[2], .05f, paintDaysOfTheWeek);
   canvas.drawText("Wed", DAYS[3], .05f, paintDaysOfTheWeek);
   canvas.drawText("Thurs", DAYS[4], .05f, paintDaysOfTheWeek);
   canvas.drawText("Fri", DAYS[5], .05f, paintDaysOfTheWeek);
   canvas.drawText("Sat", DAYS[6], .05f, paintDaysOfTheWeek);

   canvas.drawLine(.01f, .0f, .99f, .0f, paintMediumBlack);
   canvas.drawLine(.01f, .07f, .99f, .07f, paintMediumBlack);
}

Any ideas?

Was it helpful?

Solution

I fixed the issue by adding

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    setLayerType(LAYER_TYPE_SOFTWARE, paint)

to my custom view. Not sure why I needed it, and if anyone could explain it, that would be great.

OTHER TIPS

When hardware acceleration is enabled, it sometimes makes optmizations by removing drawing calls that it thinks they aren't needed.

For example if you have a View beneath another View it can decide not to render it assuming it is hidden so there's no need to render it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top