我现在能够在运动视图上绘制文本,但问题是当我绘制文本并在同一个画布上进行下一次绘制时,我的绘制文本会消失,这是因为invalidate导致屏幕重新绘制。我想保留之前的绘制并在同一画布上进行新的绘制,我该如何做到呢?
@Override
protected void onDraw(Canvas canvas) {
Paint hint = new Paint();
path = new Path();
mTextPaths = new ArrayList<Path>();
Log.v("getting mtextpaths", mTextPaths.toString());
int m;
if (strgettile != null) {
for (m = 0; m < strgettile.length(); m++) {
System.out.println(strgettile.charAt(m));
char convertst = strgettile.charAt(m);
characterToString = Character.toString(convertst);
// canvas.drawText(characterToString, x, y, hint);
// canvas.drawText(characterToString, m
// * width + x, m * height + y, foreground); //its working in
// cross
// canvas.drawText(characterToString, x, m * height + y,
// foreground); //its working for vertical
// canvas.drawText(characterToString, m
// * width + x, y, foreground); //its working in horizontal
// setSelectedTile(tile);
if (getorientation.equalsIgnoreCase("Horizontal")) {
canvas.drawText(characterToString, m * width + positionX,
positionY, foreground); // for motion event
hint.setColor(Color.BLACK);
hint.setTextSize(45);
foreground.getTextPath(characterToString, 0,
characterToString.length(), positionX * 2 / 3,
positionY - 4, path);
} else {
canvas.drawText(characterToString, positionX, m * height
+ positionY, foreground);
hint.setColor(Color.BLACK);
hint.setTextSize(45);
foreground.getTextPath(characterToString, 0,
characterToString.length(), positionX * 2 / 3,
positionY - 4, path);
}
}
}
public void setSelectedTile(String tile, String strorientations) {
// TODO Auto-generated method stub
Log.v("getting string in puzzle view ", tile);
strgettile = tile;
getorientation = strorientations;
mTextPaths.add(path);
invalidate();
}