两个要素:1显示位置,2.显示什么内容。
private PopupWindow mPopupWindow;
private ImageView queryIv;//显示位置参照物
private View mPopView;//所显示的内容
mPopView = LayoutInflater.from (getActivity()).inflate(R.layout. search_layout, null );
调用initTopPopView方法进行popupwindow的显示和隐藏
private void initTopPopView() {
if (mPopupWindow == null)
{
{
mPopupWindow = new PopupWindow(mPopView,
LayoutParams.WRAP_CONTENT ,
LayoutParams.WRAP_CONTENT ,
LayoutParams. WRAP_CONTENT, true );
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
}
if (mPopupWindow .isShowing())
{
{
mPopupWindow.dismiss();
} else {
mPopupWindow.showAsDropDown(queryIv ,
0, -10);//在queryIv底下显示
0, -10);//在queryIv底下显示
}
}