windowLayout = LayoutInflater.from(LiveActivity.this).inflate(R.layout.live_pop_more, null); window = new PopupWindow(windowLayout, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT); window.setFocusable(true); // 設置popWindow的顯示和消失動畫 window.setAnimationStyle(R.style.popwindow_anim_up_down_style); window.setOutsideTouchable(true); //這句是爲了防止彈出菜單獲取焦點之後,點擊activity的其他組件沒有響應 window.setBackgroundDrawable(new BitmapDrawable()); //popupwindow在指定位置顯示 windowLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int popupWidth = windowLayout.getMeasuredWidth(); int popupHeight = windowLayout.getMeasuredHeight(); int[] location = new int[2]; // 獲得位置 ivMore.getLocationOnScreen(location); window.showAtLocation(ivMore, Gravity.NO_GRAVITY, (location[0] + ivMore.getWidth() / 2) - popupWidth / 2, location[1] - popupHeight);
Android PopupWindow 相關設置
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.