public void PopupWindow(View parent){
View contentView = View.inflate(context,R.layout.popup_item, null);
//先把之前的销毁
dismissPopupWindow();
//-2表示包裹内容
popupwindow = new PopupWindow(contentView, -2, -2);
// 动画播放有一个前提条件: 窗体必须要有背景资源。 如果窗体没有背景,动画就播放不出来。
popupwindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
int[] location = new int[2];
view.getLocationInWindow(location);
popupwindow.showAtLocation(parent, Gravity.LEFT + Gravity.TOP, 60, location[1]);
ScaleAnimation sa = new ScaleAnimation(0.5f, 1.0f, 0.5f, 1.0f, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0.5f);
sa.setDuration(200);
AlphaAnimation aa = new AlphaAnimation(0.5f, 1.0f);
aa.setDuration(200);
AnimationSet set = new AnimationSet(false);
set.addAnimation(aa);
set.addAnimation(sa);
contentView.startAnimation(set);
}
private void dismissPopupWindow() {
if (popupwindow != null && popupwindow.isShowing()) {
popupwindow.dismiss();
popupwindow = null;
}
}