android视图视图组使ondraw和draw无效 [英] android view viewgroup invalidate ondraw and draw

查看:38
本文介绍了android视图视图组使ondraw和draw无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试编写我们自己的 MapView,我正在尝试弄清楚如何将叠加层添加到 mapview 会导致它们在其他映射 API 中被绘制

We're trying to write our own MapView, and I'm trying to figure out how adding overlays to the mapview causes them to get drawn in other mapping APIs

我有一个扩展 ViewGroup 的 MapView.我想我已经发现调用 MapView.invalidate() 会导致调用 mapview 的 dispatchDraw 方法.这听起来正确吗?

I've got a MapView that extends ViewGroup. I think I've figured out that calling MapView.invalidate() causes the mapview's dispatchDraw method to be called. Does that sound correct?

如果是这样,mapview的onDraw和draw方法是什么时候调用的?

If that's true, when is the onDraw and draw method of the mapview called?

更重要的是所有这些视图以及在任何地方都记录良好时调用的方法?

More importantly is all this view and which methods called when stuff documented well anywhere?

谢谢!

编辑这篇 SO 帖子 解释了对于扩展 ViewGroup 的类,onDraw 方法不会自动调用.如果你需要它,你必须强迫它.但是正如ebarrenchea所指出的,顺序是draw、onDraw、dispatchDraw IF所有方法都被调用

EDIT This SO post explained that for classes that extend ViewGroup, the onDraw method is not called automatically. You have to force it if you need it. But as ebarrenchea pointed out, the order is draw, onDraw, dispatchDraw IF all the methods are called

推荐答案

在您的视图组上调用 invalidate 将强制 draw 运行,进而调用 onDraw 然后是 dispatchDraw.你应该看看视图文档这里和视图源代码此处 了解更多信息.

Calling invalidate on your viewgroup will force draw to run which will in turn call onDraw and then dispatchDraw. You should have a look at the view documentation here and the View source code here for more information.

这篇关于android视图视图组使ondraw和draw无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆