当我单击缩略图时,会打开一个弹出窗口。我想在 onTouch
方法中关闭它,但问题是 onTouch
方法没有被调用。那么我怎样才能让它运行呢?如何关闭弹出窗口?
我的代码是:
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);
}
最佳答案
试试这个
View popupView = globalconstant.layoutInflater.inflate(R.layout.popup, null);
popupWindow = new PopupWindow(popupView,globalconstant.displayWidth-20,480,true);
popupWindow.setOutsideTouchable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
和onClickEvent
popupWindow.showAtLocation(v, Gravity.CENTER, 0, 15);
关于android - 弹出窗口的事件方法未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12257867/