这是我的弹出窗口。但它正在处理任何触摸事件..
popup = new PopupWindow(popupView, 300, 300, true);
popup.showAsDropDown(v, -30, 0);
popup.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));
popup.setOutsideTouchable(true);
popup.setTouchable(true);
popup.setFocusable(true);
popup.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("TAG", "Touched in the window");
return false;
}
});
请告诉我这段代码的问题..
答案 0 :(得分:0)
为了帮助那些偶然发现这个线索的人......
而不是setTouchInterceptor()
,我一直在使用setOnClickListener()
或setOnTouchListener()
,它们不是PopupWindow的成员,是的,但是我只是调用一个LayoutInflater来获取弹出窗口(View)然后将其设置为PopupWindow布局。继续使用View成员函数执行MAGIC,因为它更适合您。
代码示例:
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.my_popup_layout_id);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
//popup.setFocusable(true);
popup.setOutsideTouchable(false);
popup.showAsDropDown(anchorViewOfYourChoice, OFFSET_X, OFFSET_Y);