[英]Is it possible to invalidate Text only, but not background image on a custom View on android?
我的CustomView
绘制了一些多边形, title text
位于视图的中心。 在应用程序运行时,我需要经常更改这些视图的标题文本。 当然,我可以在设置新文本后无效,以便应用程序将重绘所有内容 - 多边形,颜色,最后是新文本 - 但我只是想知道是否有一种巧妙的方式只会使标题文本无效,留下所有背景polygons
未受影响。 当前代码如下所示:
public CustomView extends View {
private Path mPolygon1;
private Path mPolygon2;
// .. more polygons
private String mTitleText;
@Override
protected void onDraw(Canvas canvas) {
// Draws all images
canvas.drawPath(mPolygon1, mPaint);
canvas.drawPath(mPolygon2, mPaint);
// ... more polygon drawing
canvas.drawText(mTitleText, 0, mTitleText.length(), mTextPaint);
}
public void setTitle(String title) {
mTitleText = title;
invalidate(); // more clever way????
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.