Android Invalidate() 仅限单个视图
我在 RelativeLayout
上有 2 个视图
,当我尝试 view1.invalidate();
时,我只需要调用(call)onDraw单个视图
;它也调用(call)onDraw(view2绘制) )
该怎么办?
谢谢
I have 2 views on RelativeLayout
I need to invoke(call) onDraw only single view
when I try view1.invalidate();
it also invoke(call) onDraw (view2 draw)
what to do?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果当您调用 view1.invalidate(); 时,如果
view1
与view2
重叠,它将重新绘制与其重叠的每个视图。所以它会调用 view2.onDraw(); 并且由于您使用的是RelativeLayout
view1 和 view2 可能彼此重叠。if
view1
is overlapping withview2
when you callview1.invalidate();
it will re-draw every View that is overlapping with it .. so it will callview2.onDraw();
and since you are usingRelativeLayout
view1 and view2 maybe overlapped each other .我遇到了同样的问题。
最后,我发现在android 2.3中绘图缓存被禁用了。由于没有缓存,每次视图都会重绘自己,即使对方失效。
要启用缓存,请使用:
问题太旧了,但当我搜索时,谷歌将其放在第一位。我认为这对于进入这里的其他人很有用。
I met the same question.
Finally, I found that drawing cache is disabled in android 2.3. Because of no cache, each time the view will redraw itself even the other invalidated.
To make cache enable, use:
The question is too old, but google put it first when I searched. I think it is useful for others who get into here.