其他分享
首页 > 其他分享> > Android Canvas.drawText无法呈现

Android Canvas.drawText无法呈现

作者:互联网

我有一个自定义视图,在屏幕上绘制几个不同的东西.每个人都有自己的油漆对象.除了文字之外,一切都很好.它在Gingerbread中运行得很好,但ICS没有文字.

这是我的绘制方法:

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();
}

网格,选定和今天工作正常.标题和天是文本绘图,它们不起作用.

这是drawHeader方法:

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);
}

有任何想法吗?

解决方法:

我通过添加修复了这个问题

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

到我的自定义视图.不知道为什么我需要它,如果有人能解释它,那将是伟大的.

标签:android,canvas,custom-view,drawtext
来源: https://codeday.me/bug/20190626/1289292.html