在 onDraw() 中保存画布;
我试图将 Canvas 对象保存在 onDraw() 方法中。 这是因为我在 onDraw 方法中使用了 foreach 循环,结果是: canvas.DrawText (textitem, x,y, textpaint);
(我必须这样做,因为我在屏蔽区域周围绘制文本)
我现在尝试的是:
@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);
}
调试时我看到它看起来不错,但结果是空的。 让它发挥作用的最佳方法是什么?
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)
what im trying now is this :
@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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许是因为这个:
我猜你打算这样做:
Maybe that is because of this:
I guess you intend to do this instead:
您可以尝试保存位图:(我认为最好在方法的开头调用 super.onDraw(canvas); ,因为与视图相关的绘图将位于顶部)
You can try to save the bitmap: (I think it is better to call the super.onDraw(canvas); at the start on the method, because your view related drawing will be on top)