PopupWindow动画结束后dismiss崩溃解决

在个别机型PopupWindow动画结束后dismiss崩溃,日志:

<pre name="code" class="plain">E/libEGL(28187): call to OpenGL ES API with no current context (logged once per thread)
 

可能是bug,导致onAnimationEnd在错误的线程执行或者状态错误之类的,修改后问题解决:

public static PopupWindow showGainCoinPopup(Activity activity, View parent, int coinCount, final Runnable runnable){
		LayoutInflater li = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View v = li.inflate(R.layout.popupwindow_get_coin, null);
		TextView textGetCoin = (TextView) v.findViewById(R.id.textGetCoin);
		textGetCoin.setText("+" + coinCount + "金币");

		final PopupWindow pw = new PopupWindow(v, LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
		pw.setBackgroundDrawable(new BitmapDrawable());
		pw.setOutsideTouchable(false);
		pw.setFocusable(false);
		//pw.setAnimationStyle(R.anim.popup_enter);

		TranslateAnimation ani = new TranslateAnimation(0, 0, 0, -150);
		ani.setDuration(700);
		ani.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				
				// 在有些手机中dismiss会崩溃
				new Handler().post(new Runnable() {
		            @Override
		            public void run() {
		            	if (runnable!=null){
							runnable.run();
						}
						pw.dismiss();
		            }
		        });
			}
		});
		pw.showAtLocation(parent, Gravity.CENTER, 0, 0);
		v.startAnimation(ani);
		return pw;
	}


 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值