0
2

More than 3 years have passed since last update.

WindowManagerで追加したviewをアニメーションで移動させる。

Last updated at Posted at 2021-03-31

オーバーレイアプリで詰まったのでメモ
全画面に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()
            }


0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2