オーバーレイアプリで詰まったのでメモ
全画面にViewを配置してその上で動かすとイベントが取られて操作ができなくなる。
しかし、今度は動かしたいViewを配置すると、アニメーションで範囲外に出ると表示できなくなる状態だった。
なので、windowManagerへ追加したView自体を移動させたかった
// windowManager でViewを追加
val params = WindowManager.LayoutParams(
100, 100,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
or WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT)
view = inflater.inflate(R.layout.hoge_view, null)
windowManager.addView(view, params)
//横へ移動するアニメーションを準備
val animatorX = ValueAnimator.ofInt(params.x, params.x + 100).apply {
duration = animateDuration
}
animatorX.addUpdateListener {
val x = it.animatedValue as Int
if (view.isAttachedToWindow) {
//windowManagerでViewを更新させる。
params.x = x
windowManager.updateViewLayout(view, params)
}
}
AnimatorSet().apply {
play(animatorX)
start()
}