private void showPopupView() { if (mPopupWindow == null) { View view = getLayoutInflater().inflate(R.layout.newest_layout, null); mPopupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); mPopupWindow.setFocusable(true);//需要設置為ture,表示可以聚焦 //需要設置背景,用物理鍵返回的時候 mPopupWindow.setBackgroundDrawable(new BitmapDrawable(getResources())); mPopupWindow.setOutsideTouchable(true); view.setOnTouchListener(new OnTouchListener()// 需要設置,點擊之后取消popupview,即使點擊外面,也可以捕獲事件 { public boolean onTouch(View v, MotionEvent event) { if (mPopupWindow.isShowing()) { Trace.Log("-------------------onTouch------------"); mPopupWindow.dismiss(); } return false; } }); } if (mPopupWindow.isShowing()) { mPopupWindow.dismiss(); } else { View parent = findViewById(R.id.newest); mPopupWindow.showAsDropDown(parent);// 顯示再指定控件的下面 } }
新聞熱點
疑難解答
圖片精選