在个别机型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;
}