在onDraw()中保存Canvas; [英] Saving Canvas in onDraw();
本文介绍了在onDraw()中保存Canvas;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将Canvas对象保存在onDraw()方法中.
这是因为我在onDraw方法中使用了foreach循环,结果是:
canvas.DrawText(textitem,x,y,textpaint);
(我必须这样做是因为我在遮罩区域周围绘制了文本)
I'm trying to save the Canvas object in a onDraw() method.
This is because i'm using a foreach loop in the onDraw method resulting in :
canvas.DrawText (textitem , x,y, textpaint);
(i have to do this because im drawing the text around a masked area)
我现在正在尝试什么:
@Override
public void onDraw(Canvas canvas)
{
if (hasrun = false)
{
for(CustomTextViewDrawItem item : drawItemList)
{
canvas.drawText(item.Text, item.X, item.Y, textPaint);
}
if (eLabel.backgroundGradient != null)
{
canvas.drawPath(path, fillPaint);
}
canvas.save();
savedCanvas = canvas ;
}
else
{
canvas = savedCanvas;
}
hasrun = true;
super.onDraw(canvas);
}
在调试时,我认为它看起来不错,但显示为空. 什么是使此工作最佳的方法?
when debugging I see it looks ok, but comes out empty . what would be the best way to get this working ?
推荐答案
也许是因为这个原因:
if (hasrun = false)
我想您打算这样做:
if (hasrun == false)
这篇关于在onDraw()中保存Canvas;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文