WindowManager addViw 添加自定义动画效果
业务需要一个优先级较高的窗口,在任何界面都能随时弹出,且需要实现底部弹出及收起的动画效果。
选择使用**()**添加布局,在添加动画效果时发现给布局直接添加动画效果如:
val animationUp = (mContext, .pop_enter_anim);
(animationUp)
或通过的windowAnimations方法设置动画效果
= .popwin_anim
两种实现方式均无效
通过给布局最外层嵌套一层布局实现了最终的效果,代码如下,供大家参考
private var mParentView: FrameLayout? = FrameLayout(mContext)
private var inCallView = (, .layout_call, null)
private val windowManager: WindowManager by lazy {
val windowManager =
(Context.WINDOW_SERVICE) as WindowManager
mParentView?.addView(inCallView)
windowManager
}
private val params: by lazy {
val params = ()
@Suppress("DEPRECATION") //只有SYSTEM_ERROR才能覆盖到systemUI之上
= .TYPE_PHONE
=
.FLAG_NOT_FOCUSABLE or .FLAG_LAYOUT_IN_SCREEN
=
= .MATCH_PARENT
= .WRAP_CONTENT
= -1
= -1
=
params
}
fun show() {
(mParentView, params)
val animationUp =
(mContext, .pop_enter_anim);
(animationUp)
}
fun dismiss() {
val animationDown = (mContext, .pop_exit_anim);
(animationDown)
(Runnable {
(mParentView)
}, 500)
}
动画效果pop_exit_anim、pop_enter_anim
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:andro
android:shareInterpolator="false">
<!-- 平移动画 -->
<translate
android:duration="500"
android:fromYDelta="0"
android:toYDelta="100%" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:andro
android:shareInterpolator="false">
<!-- 平移动画 -->
<translate
android:duration="500"
android:fromYDelta="100%"
android:toYDelta="0" />
</set>