当我单击缩略图时,会打开一个弹出窗口。我想在onTouch
方法中解雇它,但问题是onTouch
方法没有被调用。所以我怎样才能让它运行?我怎样才能关闭弹出窗口?popupwindow的事件方法未被触发
我的代码是:
public void onItemImageClicked(View view)
{
LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.popup,null);
ImageView fullSizeImg = (ImageView) layout.findViewById(R.id.fullSizeImage);
fullSizeImg.setImageBitmap(bitmap);
fullSizeImg.setFocusable(false);
Display display = getWindowManager().getDefaultDisplay();
int deviceWidth = display.getWidth()-40;
int deviceHeight = display.getHeight()-70;
popupWindow = new PopupWindow(layout, deviceWidth, deviceHeight, true);
// display the popup in the center
popupWindow.showAtLocation(layout, Gravity.CENTER, 0, 0);
popupWindow.getMaxAvailableHeight(new View(this));
popupWindow.setFocusable(true);
popupWindow.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
popupWindow.dismiss();
return false;
}
});
popupWindow.setTouchable(true);
}
添加此行popupWindow.setBackgroundDrawable(new BitmapDrawable());并检查它会工作。 –
我已经添加过,但它不起作用。 –
加另一个\t popupWindow.setOutsideTouchable(true); –