不符合getChildDrawingOrder同步触摸事件的Android图库控制命令 [英] Android Gallery control order of touch events not in sync with getChildDrawingOrder
问题描述
我建立延伸画廊定制的Android控制。我需要的意见正在影响叠加,所以我发出
I am building a custom android control extending Gallery. I need an effect of views being overlaid so I am issuing
setSpacing(-60);
有一次,我给这个,我在画廊,1,3三个图标先绘制,然后2这是中心之一。同样的规则在 getChildDrawingOrder
定义,也由
setChildrenDrawingOrderEnabled(true);
现在的问题是意见中我已经定义订货规则的方式得到绘制。但是在画廊控制的事件是要在原来的查看订单,即1,2,3。为了更好地解释,
Now the issue is the views are getting drawn in the way I have defined the rules in ordering. But the events in the gallery control are going to the original view order i.e. 1,2,3. To explain better,
1被吸入,3绘制最后2被吸入,它们相互重叠。
这样的观点具有1 50%,2 100%和第3图的50%的
1 is drawn, 3 is drawn and finally 2 is drawn, and they overlap each other. So the view has 50% of 1, 100% of 2 and 50% of 3rd view.
但是,当我接触到的观点,机器人假定为1 50%,2 50%和3 100%是在屏幕上可见。为了澄清有点多,经过1视图的50%,如果我点击,2被集中(这是它应有的方式,因为根据我的绘图规则为,2是1顶部)。
But when I touch the views, android assumes that 50% of 1, 50% of 2 and 100% of 3 is visible on the screen. To clarify a bit more, after 50% of 1 view, if I click, 2 gets focussed (which is the way it should, because as per my drawing rule, 2 is on top of 1).
但是,当我后的视图2 50%的任何位置单击,焦点变为3,而按照图纸3的顺序是不可见的存在,2 100%是可见的,但对于图1面积的50% ,重点是视图。
But when I click anywhere after 50% of view 2, the focus goes to 3, while as per the order of drawing 3 is not visible there, 100% of 2 is visible, but for 50% of area of view 1, the focus is view 2.
能否请您对我们如何能够通过强制事件的顺序遵循视图模式在屏幕上解决它分享您的想法帮助?
Can you please help in sharing your thoughts on how we can solve it by forcing the order of events to follow the pattern of view on the screen?
推荐答案
您必须手动重新计算这些子视图的触摸区域。
You have to manually re-calculate the touch areas of those child views.
您将最有可能要重写<一个href=\"http://developer.android.com/reference/android/view/View.html#getHitRect%28android.graphics.Rect%29\"相对=nofollow> getHitRect()并返回自己的矩形
对象,其范围根据重叠区域进行了调整。
You will most likely want to override getHitRect() and return your own Rect
object, whose bounds have been adjusted according to overlapping areas.
这篇关于不符合getChildDrawingOrder同步触摸事件的Android图库控制命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!