1. 程式人生 > >android之彈出氣泡PopupWindow

android之彈出氣泡PopupWindow

private PopupWindow pop;
 //彈出氣泡PopupWindow
//                 TextView contentview=new TextView(getApplicationContext());
//                 contentview.setText(info.getPackname());

                 //自定義的佈局
                 View  contentview=View.inflate(getApplicationContext(),R.layout.popup_ruanjianmanager_item,null);

                 if(pop!=null&&pop.isShowing()){//吧舊的彈出窗體關閉掉
                     pop.dismiss();
                     pop=null;
                 }
                 pop = new PopupWindow(contentview,-2,-2);//-2 是包裹內容,-1 是填充父窗體
pop.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));//透明背景
//箭頭指向左邊和上邊,間隔0 int[] location=new int[2]; view.getLocationInWindow(location);// pop.showAtLocation(adapterView, Gravity.LEFT|Gravity.TOP,location[0],location[1]); pop.showAtLocation(adapterView, Gravity.LEFT|Gravity.TOP,60,location[1]);
在滑動listview中清除氣泡:
if
(pop!=null&&pop.isShowing()){//吧舊的彈出窗體關閉掉 pop.dismiss(); pop=null; }
在activity銷燬時清除氣泡:(因為氣泡是顯示在activity上的)

注意事項:popwindow 上加動畫時,必須給popwindow加上background,否則動畫不生效;