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,否则动画不生效;

你可能感兴趣的:(android)