猿问

悬浮窗能实现自定Animation动画效果吗?

悬浮窗能实现自定Animation动画效果吗


SMILET
浏览 1911回答 4
4回答

慕姐4208626

目前找到的方法只能调用内建的动画效果params&nbsp;=&nbsp;new&nbsp;WindowManager.LayoutParams();params.windowAnimations&nbsp;=&nbsp;android.R.style.Animation_Translucent;若改成R.style.custon_anim的话则是怎麼样都没有动画可用的方法是直接搭Handler、Runnable来updateViewLayout但是在改物件大小时会看起来不顺畅仅管已经把呼叫时间改为1ms,一样没辨法每毫秒呼叫一次更新现在是先用Runnable的方法,只做了淡出效果、物件直接放大到固定值代码大致上如下private&nbsp;void&nbsp;createFloatView(){Log.d("HuybnTag","S.createFloatView");btn_exif&nbsp;=&nbsp;new&nbsp;Button(getApplicationContext());btn_exif.setBackgroundResource(R.drawable.exif);wm&nbsp;=&nbsp;(WindowManager)&nbsp;getApplicationContext().getSystemService(Context.WINDOW_SERVICE);exif&nbsp;=&nbsp;new&nbsp;WindowManager.LayoutParams();exif.type&nbsp;=&nbsp;WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;exif.format&nbsp;=&nbsp;PixelFormat.RGBA_8888;exif.flags&nbsp;=&nbsp;WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|&nbsp;WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE&nbsp;|&nbsp;WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;exif.height&nbsp;=&nbsp;124;exif.width&nbsp;=&nbsp;124;exif.gravity&nbsp;=&nbsp;Gravity.CENTER;exif.windowAnimations&nbsp;=&nbsp;android.R.style.Animation_Translucent;.......要离开时运行这个fadeOut(btn_exif,exif);//下面这段改自网络上的代码public&nbsp;void&nbsp;fadeOut(final&nbsp;View&nbsp;notificationView,&nbsp;final&nbsp;LayoutParams&nbsp;params){animTime=300;exif.width=310;exif.height=310;final&nbsp;long&nbsp;startTime&nbsp;=&nbsp;System.currentTimeMillis();Handler&nbsp;handler&nbsp;=&nbsp;new&nbsp;Handler();handler.postDelayed(new&nbsp;Runnable(){public&nbsp;void&nbsp;run(){fadeOutHandler(notificationView,&nbsp;params,&nbsp;startTime);}},&nbsp;25);}public&nbsp;void&nbsp;fadeOutHandler(final&nbsp;View&nbsp;notificationView,&nbsp;final&nbsp;LayoutParams&nbsp;params,&nbsp;final&nbsp;long&nbsp;startTime){long&nbsp;timeNow&nbsp;=&nbsp;System.currentTimeMillis();float&nbsp;alpha&nbsp;=&nbsp;(1-&nbsp;((float)(timeNow&nbsp;-&nbsp;startTime)/animTime)&nbsp;)&nbsp;*&nbsp;1.0f;if(alpha<=0)&nbsp;alpha&nbsp;=&nbsp;0;params.alpha&nbsp;=&nbsp;alpha;Log.d("HuybnTag","alpha=&nbsp;"+alpha);wm.updateViewLayout(notificationView,&nbsp;params);if&nbsp;(timeNow-startTime<animTime){Handler&nbsp;handler&nbsp;=&nbsp;new&nbsp;Handler();handler.postDelayed(new&nbsp;Runnable(){public&nbsp;void&nbsp;run(){fadeOutHandler(notificationView,&nbsp;params,&nbsp;startTime);}},&nbsp;25);}

呼唤远方

正是丰富的运算符和表达式使C语言功能十分完善。这也是C语言的主要特点之一。C语言的运算符不仅具有不同的优先级,而且还有一个特点,就是它的结合性。在表达式中,各运算量参与运算的先后顺序不仅要遵守运算符优先级别的规定,还要受运算符结合性的制约,以便确定是自左向右进行运算还是自右向左进行运算。这种结合性是其它高级语言的运算符所没有的,因此也增加了C语言的复杂性。

一只萌萌小番薯

css3样式中的transform、animation都可以实现动画的相关效果。例如:<!DOCTYPE html><html><head><meta charset="utf-8"><title>animation动画效果</title><style>div{width:100px;height:100px;background:red;animation:myfirst 5s;-webkit-animation:myfirst 5s; /* Safari and Chrome */}@keyframes myfirst{from {background:red;}to {background:yellow;}}@-webkit-keyframes myfirst /* Safari and Chrome */{from {background:red;}to {background:yellow;}}</style></head><body><p><b>注意:</b> 该实例在 Internet Explorer 9 及更早 IE 版本是无效的。</p><div></div></body></html>
随时随地看视频慕课网APP
我要回答