该楼层疑似违规已被系统折叠隐藏此楼查看此楼
我的软件运行后会直接去调用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);
}
如果觉得《浮窗 动画特效 android 悬浮窗能实现自定Animation动画效果吗?》对你有帮助,请点赞、收藏,并留下你的观点哦!