Android:TextView onDraw() 仅一次?
我正在 onDraw() 方法中使用 TextPaint 创建自定义 TextView。 但这给我的应用程序带来了严重的问题。 我的意思是性能方面。
onDraw() 方法被一遍又一遍地调用。 但我只想它绘制一次:(
我尝试使用 setDrawingCacheEnabled(true); 但没有效果。
主布局中还有一个带有自动旋转文本视图的viewflipper, 这会导致一切重绘吗?
有人可以在这里给我一些指示吗?
I'm creating a custom TextView by using TextPaint in the onDraw() method.
however this is causing severe problems for my app.
performance wise I mean.
The onDraw() method gets called over and over again .
but i just want it to draw once :(
i tried using setDrawingCacheEnabled(true); but no effect there.
There is also a viewflipper with textviews in the main layout rotating automaticly,
could this be causing everything to redraw ?
can anyone give me some pointers here ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了启用绘图缓存之外,还尝试在 inDraw 中创建一个新的位图实例并将其传递给要绘制的 Canvas。在下次调用 onDraw 时,如果该位图不为空,则只需绘制该位图即可。我自己正在这样做,它对提高性能很有帮助,尽管现在无法复制代码(使用手机)。
至于为什么不断重绘,是否有移动重叠图形导致其失效?
As well as enabling the drawing cache, try creating a new bitmap instance in the inDraw and pass that to the Canvas to draw to. In the next call to onDraw, simply draw that bitmap if it is not null. I'm doing this myself and it works a charm to improve performance, though unable to copy the code right now (out using phone).
As for why it is being consistently redrawn, are there any moving overlapping graphics causing it to be invalidated?