为什么我的布局完全重绘我的无效它的观点吗? [英] Why is my layout completely redrawing when I invalidate one of it's views?

查看:108
本文介绍了为什么我的布局完全重绘我的无效它的观点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含多个自定义视图一个复杂的框架布局。其主要观点是一个曲线图。

I have a complex frame layout containing several custom views. The main view is a graph.

叠加的曲线图是其中重新$ P $定制视图psents一个十字指针,用户可以拖动图形周围读出有关的特定数据点的详细信息。

Overlaying the graph is a custom view which represents a cross hair pointer that the user can drag around the graph to read off detailed information about a particular data point.

框架布局捕获所有的触摸事件,呼吁每一它的点击测试方法的子视图,以确定是否触摸是该视图,然后调度触摸事件到相应的视图。

The frame layout captures all touch events, calls "hit test" methods on each of it's child views to determine if the touch was on that view then dispatches the touch event to the appropriate view.

当用户触摸十字和拖动它,我通过触摸事件,以它用来更新它的位置和本身无效十字。

When the user touches the cross hair and drags it, I pass the touch event to the cross hair which it uses to update it's position and invalidate itself.

一切工作,除了...

Everything is working except...

当我违反对这些子视图布局中的所有视图重绘。我知道这是我在开发人员选项打开显示屏幕更新。在任何时候我无效含有的FrameLayout - 或者至少不会故意。

All views in the layout are redrawing when I invalidate any of these child views. I know this as I have turned on "show screen updates" in developer options. At no point do I invalidate the containing FrameLayout - or at least, not knowingly.

当然,活动处理布局并不能否定它,我没有在子视图到父任何引用。

Certainly, the Activity handling the layout does not invalidate it and I do not have any references to the parent in the child views.

我没有贴code因为)我不知道这可能是正常的行为,二)有不少呢!和c)如果它是不正常的行为,我不知道哪个code的一部分是有问题的。当然,我很高兴地给任何可能被请求。

I haven't posted code since a) I don't know if this might be normal behaviour, b) there's a lot of it! and c) if it's not normal behaviour, I don't know which part of the code is problematic. Of course, I'm happy to give anything that might be requested.

我的最低API是2.3.3,我的目标是4.0。这发生在这两个版本,所以我怀疑我的code是问题,但哪里开始呢?

My minimum API is 2.3.3 and my target is 4.0. This happens on both of those versions so I suspect my code is the problem but where to start?

任何线索,以什么可能是怎么回事?

Any clues as to what might be going on?

推荐答案

有没有办法让查看来画只是自己,因为它依赖于它的父(它提供了它的剪辑和翻译画布通过 dispatchDraw 方法)。失效要求将失效整体视图树 - 这是你要找的答案:)

There is no way for View to draw "just itself", since it depends on it's parent (which provides it's clipped and translated Canvas via dispatchDraw method). Invalidation requires whole view tree to be invalidated - this is the answer that you're looking for :)

如果你检查出的的ViewGroup 的来源,你会发现有两个重要的方法: dispatchDraw 指定(它负责调度画事件到它的童车)和 drawChild (它通过 dispatchDraw 打了个电话,让我们如何蔡尔兹将绘制)。请注意,没有检查哪些查看开始失效,虽然有一个 RectF 指定失效区域。据我的理解 - 你需要确保你的无效化查看(交叉)并不需要整个屏幕,所以重绘将只有那部分,它其实需要

If you'll check out the source of ViewGroup, you'll find there two important methods: dispatchDraw (which responsible for dispatching draw event down to it's childs) and drawChild (which called by dispatchDraw and let's you specify how childs will be drawn). Note, that there is no check on which View starts invalidation, although there is a RectF that specifies invalidation region. As far as I understand - you need to make sure that your invalidating View (cross) doesn't takes the whole screen, so redrawn will be only that part that it actually takes.

这篇关于为什么我的布局完全重绘我的无效它的观点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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