3

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?

RufusInZen
  • 2,119
  • 1
  • 19
  • 26

2 Answers2

7

Try this:

btn.setAlpha(0f);
btn.animate().alpha(1).setDuration(1000);
Daniel Bo
  • 2,518
  • 1
  • 18
  • 29
0

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

Community
  • 1
  • 1
  • 1
    If another question on SO is similar to this and there is an answer posted there which will solve this question you should flag this as a duplicate of the the other question. – IKavanagh Aug 10 '15 at 21:19