2012-11-15 139 views
0

這是我的popupwindow。但處理任何觸摸事件..Android彈出窗口onTouchIntercept不工作

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()或​​,它們不是PopupWindow的成員,true,但我只需調用一個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); 
+0

也許它也可以使用PopupWindow.getContentView()來獲得彈出視圖,但是我手邊沒有一個測試臺環境來測試它。 – leRobot