private void initPopuptWindow() {
View contentview = LayoutInflater.from(this).inflate(R.layout.item_test, null);
// 创建一个PopupWindow
// 参数1:contentView 指定PopupWindow的内容
// 参数2:width 指定PopupWindow的width
// 参数3:height 指定PopupWindow的height
popupWindow = new PopupWindow(contentview, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams
.MATCH_PARENT, true);
//没有作用
popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.abc_ab_share_pack_holo_dark));
//设置popwindow如果点击外面区域,便关闭。
popupWindow.setOutsideTouchable(true);
popupWindow.update();
popupWindow.setAnimationStyle(R.style.popwin_anim_style);
popupWindow.setClippingEnabled(true);
popupWindow.showAsDropDown(findViewById(R.id.test_layout), Gravity.BOTTOM, 0, 0);
}
几点注意:
1.我代码里面的item_test.xml设置大小,没有作用,最后大小决定于popupwindow的尺寸(在 new popwindow的时候指定的尺寸);
2.contentview 最后会充满popwindow,所以setBackgroundDrawable设置背景没有作用(被遮住),所以可以在contentview的xml中设置背景;
3.还不清楚如何解决……