Alpha animation not working

这一生的挚爱 提交于 2019-12-12 14:28:56

问题


Pretty simple: I add a dynamic button on screen and I try to fade it out after adding, but the animation never plays. I tried adding it later when it is already rendered on the screen, but still nothing. Below is the code:

btn = new ImageButton(context);
btn.setBackgroundColor(0xFFFF0000);

params = new WindowManager.LayoutParams(
    width,height,
    WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | 
    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
    PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;

windowManager.addView(btn, params);

btn.startAnimation(new AlphaAnimation(1,0));

Any ideas?


回答1:


Try this:

btn.setAlpha(0f);
btn.animate().alpha(1).setDuration(1000);



回答2:


This answer may explain why you're getting such strange behavior if you've set the alpha to 0 in xml.



来源:https://stackoverflow.com/questions/18954629/alpha-animation-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!