Kir*_*rti 5 android text draw android-canvas
我现在可以在运动视图的画布上绘制文本问题是,当我绘制文本并在同一画布上进行下一次绘制时,我的绘制文本消失了我的意思是屏幕因无效而重新绘制,我想保留我以前的在同一个画布上绘制并进行新的绘制,我该怎么做?
@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();
}
Run Code Online (Sandbox Code Playgroud)
Tor*_*ben -3
我不会阅读那些包含所有不相关事件处理的过长且格式可怕的代码......但一般来说,如果您想在绘制之间保存画布状态,您需要明确地执行此操作。
谷歌“屏幕绘图的android”
在位图上绘制。在画布上绘制该位图。重复。
| 归档时间: |
|
| 查看次数: |
2460 次 |
| 最近记录: |