Android创建Popwindow

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

}

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值