我有以下层次结构:Activity -> PopupWindow -> CustomView
我的PopupWindow本身是一个方形的,但透明的,所以你可以看到活动坐在后台。CustomView是嵌入在PopupWindow中的一个圆圈。

到目前为止我所取得的成就是
PopupWindow外部的“一些东西”,然后将触摸事件分派到活动中。现在缺少的部分是将发生在PopupWindow内部但在CustomView (循环)之外的任何触摸事件分派给活动。
我已经知道当触觉在我的圈子之外时该如何感知。我只是很难把它下放到活动中。
在我的CustomView中,我在onTouch中有以下内容
if (radiusTouch > maxRadius) {
return false;
}在我的PopupWindow中,我已经设置了以下内容,但是它从未被调用过:
popup.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i(TAG, "PopupWindow :: onTouch()");
return false;
}
});我还需要做些什么才能把触摸活动委托给活动呢?
发布于 2011-01-11 13:43:52
考虑一下FLAG_NOT_TOUCH_MODAL:
/** 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);发布于 2011-04-28 14:30:51
尝试在您的PopupWindow实例上设置这些:
window.setBackgroundDrawable(new BitmapDrawable());
window.setOutsideTouchable(true);
和
window.setTouchable(true);
这只是个建议..。我还没试过呢。如果有用的话请告诉我。
注意:这是为了让onTouch()在触摸事件上被调用。
发布于 2010-12-06 19:07:46
遗憾的是,PopupWindow不是ViewGroup的子类,甚至不是视图的子类。然后你可以覆盖dispatchTouchEvent。您能否修改您的自定义视图以了解PopupWindow,并在圆圈外单击时调用your ()?
https://stackoverflow.com/questions/3832893
复制相似问题