很简单:我在屏幕上添加了一个动态按钮,并在添加后尝试将其淡出,但动画从未播放。当它已经呈现在屏幕上时,我尝试稍后添加它,但仍然没有。下面是代码:

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));

有任何想法吗?

最佳答案

试试这个:

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

关于android - Alpha 动画不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18954629/

10-11 00:03