[英]Is it possible to invalidate Text only, but not background image on a custom View on android?
My CustomView
draws some polygons and the title text
is located at the centre of a view. 我的
CustomView
绘制了一些多边形, title text
位于视图的中心。 As the application runs, I need to change the title text of these views frequently. 在应用程序运行时,我需要经常更改这些视图的标题文本。 Of course, I can invalidate after setting a new text so that the application will redraw everything - polygons, colors, and finally the new text - but I am just wondering if there is a clever way that only invalidates the title text, leaving all background
polygons
untouched. 当然,我可以在设置新文本后无效,以便应用程序将重绘所有内容 - 多边形,颜色,最后是新文本 - 但我只是想知道是否有一种巧妙的方式只会使标题文本无效,留下所有背景
polygons
未受影响。 The current code looks like this: 当前代码如下所示:
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????
}
}
You can use invalidate(Rect) or invalidate(left, top, right, bottom) 您可以使用invalidate(Rect)或invalidate(left,top,right,bottom)
Here is a link for more details 这是一个更多细节的链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.