今天在做一个小功能模块的时候,需要对WindowManager添加一个view且需要动画来平滑过渡。但是尝试对view添加动画,发现该动画不work。在StackOverFlow上面也有很多人遇到此问题,也没用得到解答。后面通过采用不断更新View的方式来解决此问题。如果大家有什么好的解决方案,麻烦告知一下,谢谢。
1、首先创建该View
suspendView = LayoutInflater.from(this).inflate(R.layout.tap, null);
2、添加LayoutParams
suspendLayoutParams = new LayoutParams();
suspendLayoutParams.type = LayoutParams.TYPE_PHONE; // 悬浮窗的类型,一般设为2002,表示在所有应用程序之上,但在状态栏之下
suspendLayoutParams.format = PixelFormat.RGBA_8888;
suspendLayoutParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL| LayoutParams.FLAG_NOT_FOCUSABLE; // 悬浮窗的行为,比如说不可聚焦,非模态对话框等等
suspendLayoutParams.gravity = Gravity.TOP; // 悬浮窗的对齐方式
suspendLayoutParams.alpha = 0.0f;
suspendLayoutParams.width