android – Alpha动画无法正常工作
作者:互联网
非常简单:我在屏幕上添加一个动态按钮,我尝试在添加后将其淡出,但动画永远不会播放.我稍后在屏幕上渲染时尝试添加它,但仍然没有.以下是代码:
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,animation,imagebutton 来源: https://codeday.me/bug/20190831/1776211.html