调用 invalidate(Rect) 时,ImageView 如何重绘其部分内容?

发布于 2024-08-27 23:36:35 字数 338 浏览 4 评论 0原文

我是 Android 开发新手,只是阅读文档并尝试 蜜蜂。我很困惑 ImageView 是如何只绘制一部分的 调用 invalidate(Rect) 后的内容。

我检查了ImageView.java,发现除了 onDraw(Canvas),但 onDraw(Canvas) 仅在可绘制对象为 超出视图的可见边界。 我还阅读了 View.invalidate(Rect) 的实现,我认为 该函数的关键是调用 mParent.invalidateChild(this, r); 但是,我认为父视图不知道如何绘制子视图 给定的 Rect,它最终必须调用它的子元素的一些方法 画出来。

有人研究过这部分代码吗?请你给我 一些指导?

I am new to Android development, just reading docs and trying the
APIs. I am quit confused how ImageView managed to draw just a part of
its content after an invalidate(Rect) invocation.

I've checked ImageView.java, found no other drawing method except
onDraw(Canvas), but onDraw(Canvas) only cut the drawable only if it is
beyound the view's visible boundary.
I also read the implementation of View.invalidate(Rect), I think the
key of this function is calling to
mParent.invalidateChild(this, r);
However, I think the parent view doesn't know how to draw the child in
the given Rect, it finally has to call some method of it child to
paint out.

Has anybody investigated this part of codes? Would you please give me
some guide?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

行雁书 2024-09-03 23:36:35

据我所知,有两种优化方法之一。其一,如果子视图组是视图组,则仅重绘该组中与无效区域相交的子视图。此外,画布被裁剪到该矩形的边界。这意味着需要通过总线将更少的像素移动到帧缓冲区,并且可以跳过完全剪切的绘制操作。

这是一个半有根据的猜测。几个月前我浏览了源代码,对 ViewGroup 的情况相当确定。第二个可以通过覆盖 onDraw 中的剪辑并检查它是否重绘所有内容来测试。

As far as I can gather there are two optimizations going one. For one, if the child is a viewgroup, only those children of this group are redrawn that intersect the invalidated area. Also, the canvas is clipped to the bounds of this rect. This means that less pixels have to be shuffled through the bus to the framebuffer, and that draw operations that are clipped completely can be skipped.

This is a semi-educated guess. I browsed the source a few months back and am fairly certain of the ViewGroup thing. The second one can be tested by overriding clipping in onDraw and checking if it redraws everything.

简单气质女生网名 2024-09-03 23:36:35

我猜该代码位于 View 类中。

谷歌群组中的 Romain Guy 有两个有趣的答案。

I guess that code is in the View class.

There are some two interesting answers from Romain Guy in the google group.

耳根太软 2024-09-03 23:36:35

我认为android绘制视图就像j2me中的canvas一样,所有绘制代码​​都不是直接绘制到硬件(屏幕),它只是绘制到缓冲区或可绘制或其他东西。当我们调用 View.invalidate(Rect) 时,系统将缓冲区(或可绘制对象)的矩形中的图像复制到硬件(屏幕)。

I think android draw the view just like canvas in j2me, all the draw code is not draw directly to hardware ( screen ), it just draw to a buffer or drawable or something. When we call View.invalidate(Rect), teh system copy the image in the rect of the buffer( or drawable) to hardware(screen).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文