点击Listview弹出PopWindow的用法

先来张截图:
如图点击listview中的Item在item的下方弹出一个框框,这个框框就是用的Popwindow。
 

 
用法很简单:首先写一个PopupWindow并自定义它的布局:
               LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View prView = layoutInflater.inflate(R.layout.popupwindow, null);//自定义的布局文件
mPw = new PopupWindow(prView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
然后设置点击PopupWindow之外的地方,prowindow消失:
Drawable dr = this.getResources().getDrawable(R.drawable.list_bg_click);
 
mPw.setBackgroundDrawable(dr);
 
mPw.setOutsideTouchable(true);
                同时设置这两个属性即可。
最重要的就是要确定PopupWindow的弹出位置,使其不管你点击哪个Item都会在它的下发弹出,很简单设置一句代码即可:
mPw.showAsDropDown(view);//view为Listview点击事件传过来的view.
原文地址:https://www.cnblogs.com/awkflf11/p/4612867.html