浮窗 动画特效 android,悬浮窗能实现自定Animation动画效果吗?
发布日期:2021-06-24 13:54:42 浏览次数:2 分类:技术文章

本文共 2046 字,大约阅读时间需要 6 分钟。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

我的软件运行后会直接去调用Service来显示悬浮的Button

后来在学习Dialog时认识了Animation,显示、退出对话窗时都能自定动画

就在想这样的动画能不能套用到WindowManager.LayoutParams呢?

像是LBE的悬浮圆圈在出现与消失时会有的动画

目前找到的方法只能调用内建的动画效果

params = new WindowManager.LayoutParams();

params.windowAnimations = android.R.style.Animation_Translucent;

若改成R.style.custon_anim的话则是怎麼样都没有动画

可用的方法是直接搭Handler、Runnable来updateViewLayout

但是在改物件大小时会看起来不顺畅

仅管已经把呼叫时间改为1ms,一样没辨法每毫秒呼叫一次更新

我现在是先用Runnable的方法,只做了淡出效果、物件直接放大到固定值

代码大致上如下

private void createFloatView(){

Log.d("HuybnTag","S.createFloatView");

btn_exif = new Button(getApplicationContext());

btn_exif.setBackgroundResource(R.drawable.exif);

wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);

exif = new WindowManager.LayoutParams();

exif.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;

exif.format = PixelFormat.RGBA_8888;

exif.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL

| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

exif.height = 124;

exif.width = 124;

exif.gravity = Gravity.CENTER;

exif.windowAnimations = android.R.style.Animation_Translucent;

.......

要离开时运行这个

fadeOut(btn_exif,exif);

//下面这段改自网络上的代码

public void fadeOut(final View notificationView, final LayoutParams params){

animTime=300;

exif.width=310;

exif.height=310;

final long startTime = System.currentTimeMillis();

Handler handler = new Handler();

handler.postDelayed(new Runnable(){

public void run(){

fadeOutHandler(notificationView, params, startTime);

}

}, 25);

}

public void fadeOutHandler(final View notificationView, final LayoutParams params, final long startTime){

long timeNow = System.currentTimeMillis();

float alpha = (1- ((float)(timeNow - startTime)/animTime) ) * 1.0f;

if(alpha<=0) alpha = 0;

params.alpha = alpha;

Log.d("HuybnTag","alpha= "+alpha);

wm.updateViewLayout(notificationView, params);

if (timeNow-startTime

Handler handler = new Handler();

handler.postDelayed(new Runnable(){

public void run(){

fadeOutHandler(notificationView, params, startTime);

}

}, 25);

}

转载地址:https://blog.csdn.net/weixin_33272631/article/details/117584551 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:html是描述型语言,JavaScript_JavaScript基础教程——入门必看篇,JavaScript他是一种描述性语言, - phpStudy...
下一篇:华为p10点击六下android,要被口水喷到死机的华为P10 你用的怎么样

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月12日 17时30分58秒