2011-02-09 47 views
0

我必須顯示一個popup窗口。如果我在ImageView的單擊事件中顯示它,那麼我稱它爲隱藏它。但是,當我在ImageView的Touch事件中顯示它時,請關閉事件調用,但彈出窗口不會隱藏。這個錯誤的原因是什麼?我如何解決它?PopUpWindow解僱問題

我用來顯示彈出窗口的代碼是

DisplayMetrics dm = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(dm); 
    int width = dm.widthPixels; //320  
    CabotMessageHandler.printConsole("width of screen"+width); 

    //show Popup 
    LayoutInflater inflater = (LayoutInflater) 
     this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    popupView=inflater.inflate(R.layout.gallerytoppopup, null, false); 
    pw = new PopupWindow(
     popupView, 
     width, 
     30, 
     true); 
    // The code below assumes that the root container has an id called 'main' 
    pw.setAnimationStyle(R.anim.popupanimation); 
    pw.showAtLocation(this.findViewById(R.id.webview), Gravity.TOP, 0, 30); 

回答

0

最後我發現問題。觸摸事件調用兩次,並創建兩個彈出窗口。這就是在被解僱時不隱藏Popup的原因(一個彈出窗口隱藏,另一個仍然存在)。