Android:将触摸事件委托给参考底图视图
我有以下层次结构:Android:将触摸事件委托给参考底图视图,android,events,touch,Android,Events,Touch,我有以下层次结构:活动->弹出窗口->自定义视图 我的PopupWindow本身是一个正方形,但透明,因此您可以在背景中看到活动。CustomView是嵌入在弹出窗口中的一个圆圈。 到目前为止,我所取得的成就是 用户点击绿色圆圈,我调用“一些东西” 用户在PopupWindow之外单击,触摸事件被发送到活动 现在缺少的部分是将弹出窗口内部但自定义视图(圆圈)外部发生的任何触摸事件发送到活动 我已经知道当触摸超出我的范围时如何感觉。我只是无法将其委托给活动 在我的CustomView中,我在on
活动
->弹出窗口
->自定义视图
我的PopupWindow
本身是一个正方形,但透明,因此您可以在背景中看到活动。CustomView
是嵌入在弹出窗口中的一个圆圈。
到目前为止,我所取得的成就是
PopupWindow
之外单击,触摸事件被发送到活动弹出窗口
内部但自定义视图
(圆圈)外部发生的任何触摸事件发送到活动
我已经知道当触摸超出我的范围时如何感觉。我只是无法将其委托给活动
在我的CustomView
中,我在onTouch
if (radiusTouch > maxRadius) {
return false;
}
在myPopupWindow
中,我已经设置了以下内容,但从未调用过:
popup.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i(TAG, "PopupWindow :: onTouch()");
return false;
}
});
我还需要做什么才能将触摸事件一直委托给活动?很遗憾,PopupWindow不是ViewGroup甚至View的子类。然后您可以覆盖dispatchTouchEvent。您是否可以修改自定义视图以了解PopupWindow,并在圆圈外单击时调用Disclease()。请考虑“不触摸”模式的标志:
/** Window flag: Even when this window is focusable (its
* {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events
* outside of the window to be sent to the windows behind it. Otherwise
* it will consume all pointer events itself, regardless of whether they
* are inside of the window. */
public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020;
您可以使用此代码在弹出窗口显示后更新窗口标志
FrameLayout popupContainer = (FrameLayout)contentView.getParent();
WindowManager.LayoutParams p = (WindowManager.LayoutParams)popupContainer.getLayoutParams();
p.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
WindowManager windowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
windowManager.updateViewLayout(popupContainer, p);
请尝试在PopupWindow实例上设置这些选项:
window.setBackgroundDrawable(新的BitmapDrawable())代码>
window.setOutsideTouchable(真)代码>
及
window.setTouchable(真)代码>
这只是一个建议。。。我还没有测试过。
让我知道它是否有效
[注意:这是为了在触摸事件中调用onTouch()。]您是如何创建该模型的?你是如何将点击事件发送到弹出窗口下面的视图的?Mocups是由balsamic实体模型完成的。它起作用了。我可以触及popupWindow
中的视图和活动视图。只需updateViewLayout(contentView,p)
,无contentView.getParent()