private View popView;
private void showPopupWindows(View v) {
// 一个自定义的布局,作为显示的内容
popView = LayoutInflater.from(SignActivity.this).inflate(R.layout.sign_reward, null);
popupWindow = new PopupWindow(popView,LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, true);
popupWindow.setTouchable(false);
ImageView ivScale = (ImageView) popView.findViewById(R.id.ivScale);
ivRound = (ImageView) popView.findViewById(R.id.ivRoundBg);
llRewardTxt = (LinearLayout) popView.findViewById(R.id.llRewardTxt);
myCount = new MyCount(3000, 1000);
myCount.start();
//缩放动画
ScaleAnimation animation =new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(1000);//设置动画持续时间
ivScale.setAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub 缩放动画结束后执行
llRewardTxt.setVisibility(View.VISIBLE);
ivRound.setVisibility(View.VISIBLE);
Animation round = AnimationUtils.loadAnimation(context, R.anim.round_loading_animation);
//round.setStartOffset(2000);//执行前的等待时间
ivRound.startAnimation(round);
}
});
// 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框
//popupWindow.setBackgroundDrawable(getResources().getDrawable(R.color.transparent));
popupWindow.setAnimationStyle(R.style.ActionSheetDialogAnimation);
//实例化一个ColorDrawable颜色为半透明
ColorDrawable dw = new ColorDrawable(0xb0000000);
popupWindow.setBackgroundDrawable(dw);
// 设置好参数之后再show
popupWindow.showAtLocation(v,Gravity.CENTER, 0, 0);
popupWindow.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {return false;
// 这里如果返回true的话,touch事件将被拦截 拦截后 PopupWindow的onTouchEvent不被调用,这样点击外部区域无法dismiss
}
});
}