Android Canvas Drawing Text and Change Text afterwards

房东的猫 提交于 2019-12-02 01:45:28

问题


I´ve created a costum view, and on the onDrawMethod i´ve started to draw some things. A few rects,lines, and a text.

  canvas.drawText("Hello",150,150, paint);

Now, I want to change this text, after an OnTouchEvent.

My problem is, that I don´t know, how to remove the old text. At the moment my second text, which is shown after the TouchEvent, is just overlapping my old text. Should I redraw my hole view with the new text?


回答1:


Typically you would redraw the entire view if a lot of things are going, but in this scenario you can just draw a box with the same color as the background over the old text, then display the new text on top of it.

If you have a background image, though, then it would be easier just to re-create the whole canvas.



来源:https://stackoverflow.com/questions/4423436/android-canvas-drawing-text-and-change-text-afterwards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!